Get type arguments lazily for instantiating inferred type parameter constraint#49744
Get type arguments lazily for instantiating inferred type parameter constraint#49744andrewbranch merged 2 commits intomicrosoft:mainfrom
Conversation
|
@typescript-bot perf test this |
|
Heya @andrewbranch, I've started to run the diff-based user code test suite on this PR at 5b4f1e2. You can monitor the build here. Update: The results are in! |
|
Heya @andrewbranch, I've started to run the perf test suite on this PR at 5b4f1e2. You can monitor the build here. Update: The results are in! |
|
Heya @andrewbranch, I've started to run the parallelized Definitely Typed test suite on this PR at 5b4f1e2. You can monitor the build here. |
| // type Foo<T extends string, U extends T> = [T, U]; | ||
| // type Bar<T> = T extends Foo<infer X, infer X> ? Foo<X, X> : T; | ||
| // the instantiated constraint for U is X, so we discard that inference. | ||
| const mapper = createTypeMapper(typeParameters, getEffectiveTypeArguments(typeReference, typeParameters)); |
There was a problem hiding this comment.
In the simple repro:
type AMappedType<T> = { [KeyType in keyof T]: number };
type HasM = {
m: number;
};
// Simplified repro from #48059
interface X1<
T extends HasM,
Output = AMappedType<{ s: number; } & { [k in keyof T]: number; }>
> {
tee: T;
output: Output;
}
type F1<T> = T extends X1<infer U> ? U : never;getEffectiveTypeArguments for X1<infer U> was doing all kinds of work to create the default type for Output, which eventually pulls on T who was instantiated with U, creating a circularity. But all this was in service of instantiating HasM which obviously doesn’t need to be instantiated. This simply lazifies getting those type argument types until/unless they’re needed (and also doesn’t bother filling in defaults if they’re never asked for).
|
@andrewbranch |
|
@andrewbranch Here they are:
CompilerComparison Report - main..49744
System
Hosts
Scenarios
TSServerComparison Report - main..49744
System
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fixes #48059