-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Always substitute indexed generic mapped type when getting constraint from indexed access #53066
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
Always substitute indexed generic mapped type when getting constraint from indexed access #53066
Conversation
… from indexed access
@@ -13512,7 +13512,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
} | |||
|
|||
function getConstraintFromIndexedAccess(type: IndexedAccessType) { | |||
if (isMappedTypeGenericIndexedAccess(type)) { | |||
if (isMappedTypeGenericIndexedAccess(type) || isGenericMappedType(type.objectType)) { |
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.
If the indexed access is allowed - then I think it's always safe to substitute as when the indexType
is invalid then the error is reported elsewhere anyway.
@typescript-bot test this |
Heya @weswigham, I've started to run the extended test suite on this PR at 20c9d3a. You can monitor the build here. |
Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 20c9d3a. You can monitor the build here. Update: The results are in! |
Heya @weswigham, I've started to run the perf test suite on this PR at 20c9d3a. You can monitor the build here. Update: The results are in! |
Heya @weswigham, I've started to run the diff-based top-repos suite on this PR at 20c9d3a. You can monitor the build here. Update: The results are in! |
Hey @weswigham, the results of running the DT tests are ready. |
@weswigham Here are the results of running the top-repos suite comparing Everything looks good! |
@weswigham Here they are:
CompilerComparison Report - main..53066
System
Hosts
Scenarios
TSServerComparison Report - main..53066
System
Hosts
Scenarios
StartupComparison Report - main..53066
System
Hosts
Scenarios
Developer Information: |
@Andarist @weswigham Stumbled on this PR that I hadn't seen before. Something is not right here: type Remap<K extends string> = {
[P in K as `_${P}`]: P;
};
type Key = "foo" | "bar" | "baz";
function qq1<K extends string>(obj: Remap<K>, key: keyof Remap<K>) {
let s: `_${string}` = obj[key]; // Error expected here
}
function qq2(obj: Remap<Key>, key: keyof Remap<Key>) {
let s: `_${string}` = obj[key]; // Error (as expected)
} I think your comment here is really only true when the name type isn't a remapping. |
…nstraint from indexed access (microsoft#53066)" This reverts commit abb4052.
fixes #50030