-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Mapped type and string index signature relations #17633
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit about the test.
y = x; // Error | ||
} | ||
|
||
function f2<T, K extends string>(x: { [key: string]: T }, y: Record<string, T>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the point of this test? K
isn't used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's to assert that the key type of Record
doesn't matter, only the mapped type's template type. Seems self-evident to me, but maybe it's worth a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it appears to be unused and unnecessary for the test. @ahejlsberg, is the type parameter K
needed for this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no need to have that type parameter. Will fix.
y = x; // Error | ||
} | ||
|
||
function f2<T, K extends string>(x: { [key: string]: T }, y: Record<string, T>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it appears to be unused and unnecessary for the test. @ahejlsberg, is the type parameter K
needed for this test?
With this PR a mapped type
{ [P in K]: T }
, whereK
is generic, is related to a string index signature{ [key: string]: U }
ifT
is related toU
. For example:Fixes #14548. Also fixes an unintended effect of #17382 that would allow any generic mapped type to be assignable to a string index signature (because generic mapped types have no manifest properties they were being mistaken for empty object types).