-
Notifications
You must be signed in to change notification settings - Fork 12.8k
anything is assignable to T[P] where T extends null/undefined/void/object/never #15371
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
You probably already found this out but these issues arise from extending object. |
Here's a smaller repro: function test<T extends object, P extends keyof T>(s: string, tp: T[P]): void {
tp = s; // should error
} |
To check assignability of
So |
1. `T[K]` now correctly produces `number` when `K extends string, T extends Record<K, number>`. 2. `T[K]` no longer allows any type to be assigned to it when `T extends object, K extends keyof T`. Previously both of these cases failed in getConstraintOfIndexedAccessType because both bases followed `K`'s base constraint to `string` and then incorrectly produced `any` for types (like `object`) with no string index signature. In (1), this produced an error in checkBinaryLikeExpression`. In (2), this failed to produce an error in `checkTypeRelatedTo`.
Fix is up at #17870. |
1. `T[K]` now correctly produces `number` when `K extends string, T extends Record<K, number>`. 2. `T[K]` no longer allows any type to be assigned to it when `T extends object, K extends keyof T`. Previously both of these cases failed in getConstraintOfIndexedAccessType because both bases followed `K`'s base constraint to `string` and then incorrectly produced `any` for types (like `object`) with no string index signature. In (1), this produced an error in checkBinaryLikeExpression`. In (2), this failed to produce an error in `checkTypeRelatedTo`.
The previous PR got merged by mistake and is now reverted; #17912 is the PR with the fix now. |
looks like this pr might be the reason to #12215 (comment) |
case 1
case 2
The text was updated successfully, but these errors were encountered: