diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 75be36474222f..9ee937dc5636c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20714,20 +20714,24 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments); target.instantiations.set(id, result); // Set cached result early in case we recursively invoke instantiation while eagerly computing type variable visibility below const resultObjectFlags = getObjectFlags(result); - if (result.flags & TypeFlags.ObjectFlagsType && !(resultObjectFlags & ObjectFlags.CouldContainTypeVariablesComputed)) { - const resultCouldContainTypeVariables = some(typeArguments, couldContainTypeVariables); // one of the input type arguments might be or contain the result - if (!(getObjectFlags(result) & ObjectFlags.CouldContainTypeVariablesComputed)) { - // if `result` is one of the object types we tried to make (it may not be, due to how `instantiateMappedType` works), we can carry forward the type variable containment check from the input type arguments - if (resultObjectFlags & (ObjectFlags.Mapped | ObjectFlags.Anonymous | ObjectFlags.Reference)) { - (result as ObjectFlagsType).objectFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (resultCouldContainTypeVariables ? ObjectFlags.CouldContainTypeVariables : 0); - } - // If none of the type arguments for the outer type parameters contain type variables, it follows - // that the instantiated type doesn't reference type variables. - // Intrinsics have `CouldContainTypeVariablesComputed` pre-set, so this should only cover unions and intersections resulting from `instantiateMappedType` - else { - (result as ObjectFlagsType).objectFlags |= !resultCouldContainTypeVariables ? ObjectFlags.CouldContainTypeVariablesComputed : 0; + if (result.flags & TypeFlags.ObjectFlagsType) { + let propagatingFlags = getPropagatingFlagsOfTypes(typeArguments); + if (!(resultObjectFlags & ObjectFlags.CouldContainTypeVariablesComputed)) { + const resultCouldContainTypeVariables = some(typeArguments, couldContainTypeVariables); // one of the input type arguments might be or contain the result + if (!(getObjectFlags(result) & ObjectFlags.CouldContainTypeVariablesComputed)) { + // if `result` is one of the object types we tried to make (it may not be, due to how `instantiateMappedType` works), we can carry forward the type variable containment check from the input type arguments + if (resultObjectFlags & (ObjectFlags.Mapped | ObjectFlags.Anonymous | ObjectFlags.Reference)) { + propagatingFlags |= ObjectFlags.CouldContainTypeVariablesComputed | (resultCouldContainTypeVariables ? ObjectFlags.CouldContainTypeVariables : 0); + } + // If none of the type arguments for the outer type parameters contain type variables, it follows + // that the instantiated type doesn't reference type variables. + // Intrinsics have `CouldContainTypeVariablesComputed` pre-set, so this should only cover unions and intersections resulting from `instantiateMappedType` + else { + propagatingFlags |= !resultCouldContainTypeVariables ? ObjectFlags.CouldContainTypeVariablesComputed : 0; + } } } + (result as ObjectFlagsType).objectFlags |= propagatingFlags; } } return result; diff --git a/tests/baselines/reference/nonInferrableTypePropagation4.errors.txt b/tests/baselines/reference/nonInferrableTypePropagation4.errors.txt new file mode 100644 index 0000000000000..863c8347e4dbc --- /dev/null +++ b/tests/baselines/reference/nonInferrableTypePropagation4.errors.txt @@ -0,0 +1,92 @@ +nonInferrableTypePropagation4.ts(15,22): error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<{ default: unknown; }>'. + Type 'P' is not assignable to type 'P<{ default: unknown; }>'. + Type 'unknown' is not assignable to type '{ default: unknown; }'. +nonInferrableTypePropagation4.ts(25,22): error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P>'. + Type 'P' is not assignable to type 'P>'. + Type 'unknown' is not assignable to type 'WithDefault'. +nonInferrableTypePropagation4.ts(33,22): error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<[unknown]>'. + Type 'P' is not assignable to type 'P<[unknown]>'. + Type 'unknown' is not assignable to type '[unknown]'. +nonInferrableTypePropagation4.ts(41,22): error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<{ default: { prop: unknown; }; }>'. + Type 'P' is not assignable to type 'P<{ default: { prop: unknown; }; }>'. + Type 'unknown' is not assignable to type '{ default: { prop: unknown; }; }'. +nonInferrableTypePropagation4.ts(49,22): error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<{ default: [unknown]; }>'. + Type 'P' is not assignable to type 'P<{ default: [unknown]; }>'. + Type 'unknown' is not assignable to type '{ default: [unknown]; }'. + + +==== nonInferrableTypePropagation4.ts (5 errors) ==== + // https://github.com/microsoft/TypeScript/issues/62345 + + interface P { + then: (onfulfilled: (value: T) => unknown) => unknown; + } + + interface PConstructor { + new (executor: (resolve: (value: T) => void) => void): P; + } + + declare var P: PConstructor; + + declare function foo1(x: () => P<{ default: T }>): T; + + const result1 = foo1(() => { + ~~~~~~~ +!!! error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<{ default: unknown; }>'. +!!! error TS2345: Type 'P' is not assignable to type 'P<{ default: unknown; }>'. +!!! error TS2345: Type 'unknown' is not assignable to type '{ default: unknown; }'. + return new P((resolve) => { + resolve; + }); + }); + + type WithDefault = { default: T }; + + declare function foo2(x: () => P>): T; + + const result2 = foo2(() => { + ~~~~~~~ +!!! error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P>'. +!!! error TS2345: Type 'P' is not assignable to type 'P>'. +!!! error TS2345: Type 'unknown' is not assignable to type 'WithDefault'. + return new P((resolve) => { + resolve; + }); + }); + + declare function foo3(x: () => P<[T]>): T; + + const result3 = foo3(() => { + ~~~~~~~ +!!! error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<[unknown]>'. +!!! error TS2345: Type 'P' is not assignable to type 'P<[unknown]>'. +!!! error TS2345: Type 'unknown' is not assignable to type '[unknown]'. + return new P((resolve) => { + resolve; + }); + }); + + declare function foo4(x: () => P<{ default: { prop: T } }>): T; + + const result4 = foo4(() => { + ~~~~~~~ +!!! error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<{ default: { prop: unknown; }; }>'. +!!! error TS2345: Type 'P' is not assignable to type 'P<{ default: { prop: unknown; }; }>'. +!!! error TS2345: Type 'unknown' is not assignable to type '{ default: { prop: unknown; }; }'. + return new P((resolve) => { + resolve; + }); + }); + + declare function foo5(x: () => P<{ default: [T] }>): T; + + const result5 = foo5(() => { + ~~~~~~~ +!!! error TS2345: Argument of type '() => P' is not assignable to parameter of type '() => P<{ default: [unknown]; }>'. +!!! error TS2345: Type 'P' is not assignable to type 'P<{ default: [unknown]; }>'. +!!! error TS2345: Type 'unknown' is not assignable to type '{ default: [unknown]; }'. + return new P((resolve) => { + resolve; + }); + }); + \ No newline at end of file diff --git a/tests/baselines/reference/nonInferrableTypePropagation4.symbols b/tests/baselines/reference/nonInferrableTypePropagation4.symbols new file mode 100644 index 0000000000000..b8e36e844bf69 --- /dev/null +++ b/tests/baselines/reference/nonInferrableTypePropagation4.symbols @@ -0,0 +1,154 @@ +//// [tests/cases/compiler/nonInferrableTypePropagation4.ts] //// + +=== nonInferrableTypePropagation4.ts === +// https://github.com/microsoft/TypeScript/issues/62345 + +interface P { +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 2, 12)) + + then: (onfulfilled: (value: T) => unknown) => unknown; +>then : Symbol(P.then, Decl(nonInferrableTypePropagation4.ts, 2, 16)) +>onfulfilled : Symbol(onfulfilled, Decl(nonInferrableTypePropagation4.ts, 3, 9)) +>value : Symbol(value, Decl(nonInferrableTypePropagation4.ts, 3, 23)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 2, 12)) +} + +interface PConstructor { +>PConstructor : Symbol(PConstructor, Decl(nonInferrableTypePropagation4.ts, 4, 1)) + + new (executor: (resolve: (value: T) => void) => void): P; +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 7, 7)) +>executor : Symbol(executor, Decl(nonInferrableTypePropagation4.ts, 7, 10)) +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 7, 21)) +>value : Symbol(value, Decl(nonInferrableTypePropagation4.ts, 7, 31)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 7, 7)) +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 7, 7)) +} + +declare var P: PConstructor; +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>PConstructor : Symbol(PConstructor, Decl(nonInferrableTypePropagation4.ts, 4, 1)) + +declare function foo1(x: () => P<{ default: T }>): T; +>foo1 : Symbol(foo1, Decl(nonInferrableTypePropagation4.ts, 10, 28)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 12, 22)) +>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 12, 25)) +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 12, 37)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 12, 22)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 12, 22)) + +const result1 = foo1(() => { +>result1 : Symbol(result1, Decl(nonInferrableTypePropagation4.ts, 14, 5)) +>foo1 : Symbol(foo1, Decl(nonInferrableTypePropagation4.ts, 10, 28)) + + return new P((resolve) => { +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 15, 16)) + + resolve; +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 15, 16)) + + }); +}); + +type WithDefault = { default: T }; +>WithDefault : Symbol(WithDefault, Decl(nonInferrableTypePropagation4.ts, 18, 3)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 20, 17)) +>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 20, 23)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 20, 17)) + +declare function foo2(x: () => P>): T; +>foo2 : Symbol(foo2, Decl(nonInferrableTypePropagation4.ts, 20, 37)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 22, 22)) +>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 22, 25)) +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>WithDefault : Symbol(WithDefault, Decl(nonInferrableTypePropagation4.ts, 18, 3)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 22, 22)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 22, 22)) + +const result2 = foo2(() => { +>result2 : Symbol(result2, Decl(nonInferrableTypePropagation4.ts, 24, 5)) +>foo2 : Symbol(foo2, Decl(nonInferrableTypePropagation4.ts, 20, 37)) + + return new P((resolve) => { +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 25, 16)) + + resolve; +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 25, 16)) + + }); +}); + +declare function foo3(x: () => P<[T]>): T; +>foo3 : Symbol(foo3, Decl(nonInferrableTypePropagation4.ts, 28, 3)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 30, 22)) +>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 30, 25)) +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 30, 22)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 30, 22)) + +const result3 = foo3(() => { +>result3 : Symbol(result3, Decl(nonInferrableTypePropagation4.ts, 32, 5)) +>foo3 : Symbol(foo3, Decl(nonInferrableTypePropagation4.ts, 28, 3)) + + return new P((resolve) => { +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 33, 16)) + + resolve; +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 33, 16)) + + }); +}); + +declare function foo4(x: () => P<{ default: { prop: T } }>): T; +>foo4 : Symbol(foo4, Decl(nonInferrableTypePropagation4.ts, 36, 3)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 38, 22)) +>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 38, 25)) +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 38, 37)) +>prop : Symbol(prop, Decl(nonInferrableTypePropagation4.ts, 38, 48)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 38, 22)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 38, 22)) + +const result4 = foo4(() => { +>result4 : Symbol(result4, Decl(nonInferrableTypePropagation4.ts, 40, 5)) +>foo4 : Symbol(foo4, Decl(nonInferrableTypePropagation4.ts, 36, 3)) + + return new P((resolve) => { +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 41, 16)) + + resolve; +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 41, 16)) + + }); +}); + +declare function foo5(x: () => P<{ default: [T] }>): T; +>foo5 : Symbol(foo5, Decl(nonInferrableTypePropagation4.ts, 44, 3)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 46, 22)) +>x : Symbol(x, Decl(nonInferrableTypePropagation4.ts, 46, 25)) +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>default : Symbol(default, Decl(nonInferrableTypePropagation4.ts, 46, 37)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 46, 22)) +>T : Symbol(T, Decl(nonInferrableTypePropagation4.ts, 46, 22)) + +const result5 = foo5(() => { +>result5 : Symbol(result5, Decl(nonInferrableTypePropagation4.ts, 48, 5)) +>foo5 : Symbol(foo5, Decl(nonInferrableTypePropagation4.ts, 44, 3)) + + return new P((resolve) => { +>P : Symbol(P, Decl(nonInferrableTypePropagation4.ts, 0, 0), Decl(nonInferrableTypePropagation4.ts, 10, 11)) +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 49, 16)) + + resolve; +>resolve : Symbol(resolve, Decl(nonInferrableTypePropagation4.ts, 49, 16)) + + }); +}); + diff --git a/tests/baselines/reference/nonInferrableTypePropagation4.types b/tests/baselines/reference/nonInferrableTypePropagation4.types new file mode 100644 index 0000000000000..6c00543efcb2e --- /dev/null +++ b/tests/baselines/reference/nonInferrableTypePropagation4.types @@ -0,0 +1,208 @@ +//// [tests/cases/compiler/nonInferrableTypePropagation4.ts] //// + +=== nonInferrableTypePropagation4.ts === +// https://github.com/microsoft/TypeScript/issues/62345 + +interface P { + then: (onfulfilled: (value: T) => unknown) => unknown; +>then : (onfulfilled: (value: T) => unknown) => unknown +> : ^ ^^ ^^^^^ +>onfulfilled : (value: T) => unknown +> : ^ ^^ ^^^^^ +>value : T +> : ^ +} + +interface PConstructor { + new (executor: (resolve: (value: T) => void) => void): P; +>executor : (resolve: (value: T) => void) => void +> : ^ ^^ ^^^^^ +>resolve : (value: T) => void +> : ^ ^^ ^^^^^ +>value : T +> : ^ +} + +declare var P: PConstructor; +>P : PConstructor +> : ^^^^^^^^^^^^ + +declare function foo1(x: () => P<{ default: T }>): T; +>foo1 : (x: () => P<{ default: T; }>) => T +> : ^ ^^ ^^ ^^^^^ +>x : () => P<{ default: T; }> +> : ^^^^^^ +>default : T +> : ^ + +const result1 = foo1(() => { +>result1 : unknown +> : ^^^^^^^ +>foo1(() => { return new P((resolve) => { resolve; });}) : unknown +> : ^^^^^^^ +>foo1 : (x: () => P<{ default: T; }>) => T +> : ^ ^^ ^^ ^^^^^ +>() => { return new P((resolve) => { resolve; });} : () => P +> : ^^^^^^^^^^^^^^^^ + + return new P((resolve) => { +>new P((resolve) => { resolve; }) : P +> : ^^^^^^^^^^ +>P : PConstructor +> : ^^^^^^^^^^^^ +>(resolve) => { resolve; } : (resolve: (value: unknown) => void) => void +> : ^ ^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^ +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + resolve; +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + }); +}); + +type WithDefault = { default: T }; +>WithDefault : WithDefault +> : ^^^^^^^^^^^^^^ +>default : T +> : ^ + +declare function foo2(x: () => P>): T; +>foo2 : (x: () => P>) => T +> : ^ ^^ ^^ ^^^^^ +>x : () => P> +> : ^^^^^^ + +const result2 = foo2(() => { +>result2 : unknown +> : ^^^^^^^ +>foo2(() => { return new P((resolve) => { resolve; });}) : unknown +> : ^^^^^^^ +>foo2 : (x: () => P>) => T +> : ^ ^^ ^^ ^^^^^ +>() => { return new P((resolve) => { resolve; });} : () => P +> : ^^^^^^^^^^^^^^^^ + + return new P((resolve) => { +>new P((resolve) => { resolve; }) : P +> : ^^^^^^^^^^ +>P : PConstructor +> : ^^^^^^^^^^^^ +>(resolve) => { resolve; } : (resolve: (value: unknown) => void) => void +> : ^ ^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^ +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + resolve; +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + }); +}); + +declare function foo3(x: () => P<[T]>): T; +>foo3 : (x: () => P<[T]>) => T +> : ^ ^^ ^^ ^^^^^ +>x : () => P<[T]> +> : ^^^^^^ + +const result3 = foo3(() => { +>result3 : unknown +> : ^^^^^^^ +>foo3(() => { return new P((resolve) => { resolve; });}) : unknown +> : ^^^^^^^ +>foo3 : (x: () => P<[T]>) => T +> : ^ ^^ ^^ ^^^^^ +>() => { return new P((resolve) => { resolve; });} : () => P +> : ^^^^^^^^^^^^^^^^ + + return new P((resolve) => { +>new P((resolve) => { resolve; }) : P +> : ^^^^^^^^^^ +>P : PConstructor +> : ^^^^^^^^^^^^ +>(resolve) => { resolve; } : (resolve: (value: unknown) => void) => void +> : ^ ^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^ +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + resolve; +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + }); +}); + +declare function foo4(x: () => P<{ default: { prop: T } }>): T; +>foo4 : (x: () => P<{ default: { prop: T; }; }>) => T +> : ^ ^^ ^^ ^^^^^ +>x : () => P<{ default: { prop: T; }; }> +> : ^^^^^^ +>default : { prop: T; } +> : ^^^^^^^^ ^^^ +>prop : T +> : ^ + +const result4 = foo4(() => { +>result4 : unknown +> : ^^^^^^^ +>foo4(() => { return new P((resolve) => { resolve; });}) : unknown +> : ^^^^^^^ +>foo4 : (x: () => P<{ default: { prop: T; }; }>) => T +> : ^ ^^ ^^ ^^^^^ +>() => { return new P((resolve) => { resolve; });} : () => P +> : ^^^^^^^^^^^^^^^^ + + return new P((resolve) => { +>new P((resolve) => { resolve; }) : P +> : ^^^^^^^^^^ +>P : PConstructor +> : ^^^^^^^^^^^^ +>(resolve) => { resolve; } : (resolve: (value: unknown) => void) => void +> : ^ ^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^ +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + resolve; +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + }); +}); + +declare function foo5(x: () => P<{ default: [T] }>): T; +>foo5 : (x: () => P<{ default: [T]; }>) => T +> : ^ ^^ ^^ ^^^^^ +>x : () => P<{ default: [T]; }> +> : ^^^^^^ +>default : [T] +> : ^^^ + +const result5 = foo5(() => { +>result5 : unknown +> : ^^^^^^^ +>foo5(() => { return new P((resolve) => { resolve; });}) : unknown +> : ^^^^^^^ +>foo5 : (x: () => P<{ default: [T]; }>) => T +> : ^ ^^ ^^ ^^^^^ +>() => { return new P((resolve) => { resolve; });} : () => P +> : ^^^^^^^^^^^^^^^^ + + return new P((resolve) => { +>new P((resolve) => { resolve; }) : P +> : ^^^^^^^^^^ +>P : PConstructor +> : ^^^^^^^^^^^^ +>(resolve) => { resolve; } : (resolve: (value: unknown) => void) => void +> : ^ ^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^ +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + resolve; +>resolve : (value: unknown) => void +> : ^ ^^^^^^^^^^^^^^ + + }); +}); + diff --git a/tests/cases/compiler/nonInferrableTypePropagation4.ts b/tests/cases/compiler/nonInferrableTypePropagation4.ts new file mode 100644 index 0000000000000..a7591d2f00454 --- /dev/null +++ b/tests/cases/compiler/nonInferrableTypePropagation4.ts @@ -0,0 +1,56 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/62345 + +interface P { + then: (onfulfilled: (value: T) => unknown) => unknown; +} + +interface PConstructor { + new (executor: (resolve: (value: T) => void) => void): P; +} + +declare var P: PConstructor; + +declare function foo1(x: () => P<{ default: T }>): T; + +const result1 = foo1(() => { + return new P((resolve) => { + resolve; + }); +}); + +type WithDefault = { default: T }; + +declare function foo2(x: () => P>): T; + +const result2 = foo2(() => { + return new P((resolve) => { + resolve; + }); +}); + +declare function foo3(x: () => P<[T]>): T; + +const result3 = foo3(() => { + return new P((resolve) => { + resolve; + }); +}); + +declare function foo4(x: () => P<{ default: { prop: T } }>): T; + +const result4 = foo4(() => { + return new P((resolve) => { + resolve; + }); +}); + +declare function foo5(x: () => P<{ default: [T] }>): T; + +const result5 = foo5(() => { + return new P((resolve) => { + resolve; + }); +});