-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Check for any types in strict expectType #43
Comments
(FWIW the fact that there's no good way to handle |
This is a good catch! Didn't think about that one.
I don't believe this is a reason. The reason is because they work comment based, thus a string. Meaning they have a I will take a look what I can do to prevent this behaviour. Thanks for reporting! |
I wrote typings-checker which eventually became dtslint. String comparison was expedient, but resilience in the face of Happy to give feedback on anything you come up with. |
Instead of using the
More info here https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3.11.2 @orta Do you have any feedback on this? If we do a strict type assertion, we don't want that |
I tested it more thorougly and it looks like These are use cases where it fails expectType<string>(m<any>());
expectType<any>(m<string>());
expectType<Observable<string | number | any> | Observable<Date> | Observable<Symbol>>(
one<Observable<Date> | Observable<Symbol> | Observable<number | string>>()
); I will probably change the error message though Currently we have
But now it could be in both directions. So I think it makes sense to change it to
@sindresorhus What do you think regarding the error message? |
@SamVerschueren the error message about "declared too wide" more precisely describes the problem, so it would be sad to lose. You could run the one-way assignability checks only if BTW, I asked Anders about this at tsconf this weekend. |
Good idea regarding the error message. Will try to keep it. I agree that it's pretty descriptive. I know that it's a private API, but to be honest, I stopped caring after reading this PR microsoft/TypeScript#9943. It got stale for nothing in my opinion, the PR was fine as it was. I'm not part of the team though, and I don't know what direction they want to go to. So from a user point of view, it's easy for me to say that... Thanks for asking Anders about this API, it's good to know that it might not be entirely battle tested in the real world. But for now, it looks like the only correct solution which works and which takes |
This is now fixed and will be part of the next release. Thanks for bringing this to my attention :)! Great work! |
This is released in |
I would expect this to fail, especially with "strict" type assertions:
Everything is assignable to
any
andany
is assignable to everything, so the check passes.It's not entirely clear to me what the ideal behavior is here for types like
any[]
or forany
s in larger types like{name: string; metadata: any;}
:But a check that the argument to
expectType
isn't anany
type if the expected type is non-any
would make sense:You might find this 2ality post interesting, the comments point out some drawbacks of testing types by looking for assignability both ways.
any
is one, but there may also be some issues related to distributing conditional types.The text was updated successfully, but these errors were encountered: