-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Exact type assertions #21
Conversation
10d306c
to
52a32e5
Compare
Hi @BendingBender. We should take a look if we can get this one merged! Before I dive into the details, could you explain what your changes actually do? It will probably help me in understanding what changed and what exactly is going on. Thanks for this PR btw, it's open for too long :). |
This PR is blocked right now. The reason for this is that it uses string matching to assert the types. This means that We have to find a way to do this on type system level or something so the order doesn't matter and users like it because a minor change in the type definitions doesn't cause a headache. If people have ideas on how to fix this, feel free to chime in. @orta Do you have an idea how we would be able to do this? Some TS API or something that could help us out with this? |
I'm not sure how much of this is public api, but you can get a type checker from the program ( Then you're kinda at a dead end, see: microsoft/TypeScript#9879 microsoft/TypeScript#9943 That said, it looks like https://www.npmjs.com/package/ts-simple-type looks like it can handle most cases |
That's a good pointer in a direction I like. Played with it a little but it's pretty hard due to the fact that the TS compiler isn't really co-operating 😂. For example expectType<string>(concat('foo', 'bar')); I want to infer the return type of the concat() call, but it looks like I tried everything without luck. Let's asume that typeChecker.getResolvedSignature(node.expression.arguments[0]);
//=> 'Debug Failure. False expression.'
typeChecker.getResolvedSignature(node.expression.arguments[0].expression);
//=> 'Debug Failure. Branch in \'resolveSignature\' should be unreachable. SyntaxKind: Identifier' The |
I got things working 🎉 I can now detect that the type is too wide. But because I don't use string matching Still have to fix some things though, but this approach already looks promising. |
It works for almost everything, except when I wanted to add tests for RxJS, it fails. I created an issue in We really need that type relation API... |
Everything works locally. Tests are added. I only have to wrap it up tomorrow and then this is done. I removed I know, this is not an ideal situation, but it was the only way I could make it work like I wanted it to work... I hope the TypeScript team sees the benefits in exposing that API publically so I don't have to workaround the problem... So this functionality is coming to you in this weekend. |
66702dd
to
1f79e98
Compare
Implemented in e4c78c7 |
This PR implements exact type assertions as discussed here.
Waiting for #20.