🤖 Pick PR #59121 (Fixed regression in signature insta...) into release-5.5 (#59204)

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
TypeScript Bot 2024-07-16 11:36:44 -07:00 committed by GitHub
parent 0d4ffed756
commit cf167dbb6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 99 additions and 2 deletions

View File

@ -15942,7 +15942,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function createSignatureTypeMapper(signature: Signature, typeArguments: readonly Type[] | undefined): TypeMapper {
return createTypeMapper(signature.typeParameters!, typeArguments);
return createTypeMapper(sameMap(signature.typeParameters!, tp => tp.mapper ? instantiateType(tp, tp.mapper) : tp), typeArguments);
}
function getErasedSignature(signature: Signature): Signature {

View File

@ -1,7 +1,7 @@
//// [tests/cases/compiler/excessiveStackDepthFlatArray.ts] ////
=== Performance Stats ===
Instantiation count: 1,000
Instantiation count: 1,000 -> 2,500
=== index.tsx ===
interface MiddlewareArray<T> extends Array<T> {}

View File

@ -0,0 +1,39 @@
//// [tests/cases/compiler/genericCallInferenceConditionalType1.ts] ////
=== genericCallInferenceConditionalType1.ts ===
// https://github.com/microsoft/TypeScript/issues/59108
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown;
>f : Symbol(f, Decl(genericCallInferenceConditionalType1.ts, 2, 13))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 2, 18))
>f : Symbol(f, Decl(genericCallInferenceConditionalType1.ts, 2, 21))
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 2, 25))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 2, 18))
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 2, 47))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 2, 18))
declare const g: <T extends unknown>(x: { foo: T }) => unknown;
>g : Symbol(g, Decl(genericCallInferenceConditionalType1.ts, 3, 13))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 3, 18))
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 3, 37))
>foo : Symbol(foo, Decl(genericCallInferenceConditionalType1.ts, 3, 41))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 3, 18))
const h = f(g);
>h : Symbol(h, Decl(genericCallInferenceConditionalType1.ts, 5, 5))
>f : Symbol(f, Decl(genericCallInferenceConditionalType1.ts, 2, 13))
>g : Symbol(g, Decl(genericCallInferenceConditionalType1.ts, 3, 13))
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown;
>FirstParameter : Symbol(FirstParameter, Decl(genericCallInferenceConditionalType1.ts, 5, 15))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 7, 20))
>T : Symbol(T, Decl(genericCallInferenceConditionalType1.ts, 7, 20))
>x : Symbol(x, Decl(genericCallInferenceConditionalType1.ts, 7, 36))
>P : Symbol(P, Decl(genericCallInferenceConditionalType1.ts, 7, 44))
>P : Symbol(P, Decl(genericCallInferenceConditionalType1.ts, 7, 44))
type X = FirstParameter<typeof h>["foo"];
>X : Symbol(X, Decl(genericCallInferenceConditionalType1.ts, 7, 73))
>FirstParameter : Symbol(FirstParameter, Decl(genericCallInferenceConditionalType1.ts, 5, 15))
>h : Symbol(h, Decl(genericCallInferenceConditionalType1.ts, 5, 5))

View File

@ -0,0 +1,45 @@
//// [tests/cases/compiler/genericCallInferenceConditionalType1.ts] ////
=== genericCallInferenceConditionalType1.ts ===
// https://github.com/microsoft/TypeScript/issues/59108
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown;
>f : <T>(f: (x: T) => unknown) => (x: T) => unknown
> : ^ ^^ ^^ ^^^^^
>f : (x: T) => unknown
> : ^ ^^ ^^^^^
>x : T
> : ^
>x : T
> : ^
declare const g: <T extends unknown>(x: { foo: T }) => unknown;
>g : <T extends unknown>(x: { foo: T; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
>x : { foo: T; }
> : ^^^^^^^ ^^^
>foo : T
> : ^
const h = f(g);
>h : <T extends unknown>(x: { foo: T; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^
>f(g) : <T extends unknown>(x: { foo: T; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^
>f : <T>(f: (x: T) => unknown) => (x: T) => unknown
> : ^ ^^ ^^ ^^^^^
>g : <T extends unknown>(x: { foo: T; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown;
>FirstParameter : FirstParameter<T>
> : ^^^^^^^^^^^^^^^^^
>x : P
> : ^
type X = FirstParameter<typeof h>["foo"];
>X : unknown
> : ^^^^^^^
>h : <T extends unknown>(x: { foo: T; }) => unknown
> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^

View File

@ -0,0 +1,13 @@
// @strict: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/59108
declare const f: <T>(f: (x: T) => unknown) => (x: T) => unknown;
declare const g: <T extends unknown>(x: { foo: T }) => unknown;
const h = f(g);
type FirstParameter<T> = T extends (x: infer P) => unknown ? P : unknown;
type X = FirstParameter<typeof h>["foo"];