-
Notifications
You must be signed in to change notification settings - Fork 12.8k
keyof NonNullable<T> cannot be used to index type T #23368
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
Comments
Possibly related: function f<T extends string | undefined>(t: T): NonNullable<T> {
if (t === undefined) throw "bad";
return t;
} |
@Andy-MS I think that's just because narrowing doesn't apply higher order types right now. |
Hey everyone. I was trying to figure this issue out and I realized that If this issue is worth fixing, I suggest adding the following rule to the
This rule should be applied before the rule that reduces Example of the first rule being applied:
Right now, an error is raised, but for the wrong reasons. It tries to assign The original issue doesn't occur anymore but this does function f1<T>(keyofT: keyof T, keyofNonNullT: keyof NonNullable<T>) {
keyofT = keyofNonNullT // should not raise error but does on the latest master
} EDIT: Okay, I implemented the new rule but turns out this isn't quite enough to fix the second example because |
Update: I implemented a special case for checks like Is that kind of logic too much of a special case for the type checker? |
TypeScript Version: 2.9.0-dev.20180412
Code
Expected behavior:
No error.
Actual behavior:
Related issues: #19461
The text was updated successfully, but these errors were encountered: