-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Questions: check if type is assignable to other #357
Comments
Yeah, this would be very useful. We probably have to wait for this issue to be resolved in the TypeScript compiler API: microsoft/TypeScript#9879 In the meantime, you might have to roll with your own implementation :( |
Wow, I was almost sure there was something in the TS API for this. How crazy would it to be to print two types, create a project with a single file, try the assignment and then type check the file? Do you think it would work? |
Haha! That would work. You could just create some temporary dummy file within your existing project then call |
@dsherret @lazarljubenovic I'm doing just that to test a type utility library where I need to check for failures . With tools like tsd-check that run at compile time you cannot make the test fail (cannot leave compile errors in the project)... so I did basically what you mention: https://github.com/cancerberoSgx/tsd-check-runtime/ BTW is based on ts-simple-ast, sorry, ts-morph. I added lots of features but still its execution time is acceptable ... and I'm creating a new project for each test and emitting diagnostics, each time, |
Need a bit of help here: how do I check if types assignable to one other?
Scenario 1: I have two nodes, I can get their types via
getType()
. How do I check if A is assignable to B and if B is assignable to A?Scenario 2: I have one node, and I want to check if it's assignable to custom type that I will conclude based on a string (template in a framework). To give context, user does something like (let's assume Angular syntax for familiarity)
*ngIf="foo"
. In my framework,ngIf
doesn't exist runtime and there's noboolean
type anywhere where I cangetType
it -- so how can I create it? What about more complex cases?I was expecting some
Type
constructors, but browsing through.d.ts
files gives me nothing. Also assignable gives no results. I see the docs mention the type checker but I don't see anything useful there either based on method names.Any pointers would be appreciated. 😄
The text was updated successfully, but these errors were encountered: