-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Unable to add numeric types that are not simply 'number' #17069
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
Milestone
Comments
Related: #15501 |
sandersn
added a commit
that referenced
this issue
Aug 17, 2017
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 |
sandersn
added a commit
that referenced
this issue
Aug 18, 2017
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm trying to rewrite the signature of
sum
fromcore.ts
in our compiler (see #16823), but I'm getting this error:Note that I can't declare
sum
asbecause then TypeScript would infer all of the properties in each element for
K
. So I do need another type argumentT
for the indirection.For a simpler repro:
Related is #15645.
The text was updated successfully, but these errors were encountered: