-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Casting generics ignores --strictNullCheck #13513
Comments
This might be related to #10717 and https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-function-parameters-bivariant |
@rbuckton does this get fixed by your recent change? |
@RyanCavanaugh: if you mean #13487 then no, I do not believe it addresses this issue. In this case we are running afoul of parameter bivariance and how we handle structural typing. Though the checker sees that the type arguments are not assignable, we continue on to a structural check. During the structural check, we end up comparing the assignability of the |
Is this an example of the same or a similar issue (in v2.1.5)? Would #10717/#13257 fix this? class A {
constructor(readonly message: string) {}
}
class B extends A {
lastCharacter() {
return this.message.substring(this.message.length - 1);
}
}
const pick: (s: string) => Promise<B> = (s: string) =>
Promise.resolve(new A(s)); |
TypeScript Version: 2.1.5
Code
Minimal example that compiles just fine:
Small usage example in which I encountered the bug:
Expected behavior:
A compile error: the type
Promise<string | undefined>
does not match the typePromise<string>
. I should not be able to castundefined
tostring
.Actual behavior:
No errors.
The text was updated successfully, but these errors were encountered: