diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6ae60c97e56fc..444bee8c7b38c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16300,7 +16300,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getTypeArguments(type: TypeReference): readonly Type[] { if (!type.resolvedTypeArguments) { if (!pushTypeResolution(type, TypeSystemPropertyName.ResolvedTypeArguments)) { - return type.target.localTypeParameters?.map(() => errorType) || emptyArray; + return concatenate(type.target.outerTypeParameters, type.target.localTypeParameters?.map(() => errorType)) || emptyArray; } const node = type.node; const typeArguments = !node ? emptyArray : @@ -16311,7 +16311,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { type.resolvedTypeArguments ??= type.mapper ? instantiateTypes(typeArguments, type.mapper) : typeArguments; } else { - type.resolvedTypeArguments ??= type.target.localTypeParameters?.map(() => errorType) || emptyArray; + type.resolvedTypeArguments ??= concatenate(type.target.outerTypeParameters, type.target.localTypeParameters?.map(() => errorType) || emptyArray); error( type.node || currentNode, type.target.symbol ? Diagnostics.Type_arguments_for_0_circularly_reference_themselves : Diagnostics.Tuple_type_arguments_circularly_reference_themselves, diff --git a/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.errors.txt b/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.errors.txt new file mode 100644 index 0000000000000..53282f471d806 --- /dev/null +++ b/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.errors.txt @@ -0,0 +1,13 @@ +circularTypeArgumentsLocalAndOuterNoCrash1.ts(5,12): error TS4109: Type arguments for 'NumArray' circularly reference themselves. + + +==== circularTypeArgumentsLocalAndOuterNoCrash1.ts (1 errors) ==== + // https://github.com/microsoft/TypeScript/issues/59062 + + function f<_T, _S>() { + interface NumArray extends Array {} + type X = NumArray; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4109: Type arguments for 'NumArray' circularly reference themselves. + } + \ No newline at end of file diff --git a/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.symbols b/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.symbols new file mode 100644 index 0000000000000..ba186a74b88b2 --- /dev/null +++ b/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.symbols @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts] //// + +=== circularTypeArgumentsLocalAndOuterNoCrash1.ts === +// https://github.com/microsoft/TypeScript/issues/59062 + +function f<_T, _S>() { +>f : Symbol(f, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 0, 0)) +>_T : Symbol(_T, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 11)) +>_S : Symbol(_S, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 14)) + + interface NumArray extends Array {} +>NumArray : Symbol(NumArray, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 22)) +>T : Symbol(T, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 21)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 21)) + + type X = NumArray; +>X : Symbol(X, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 58)) +>NumArray : Symbol(NumArray, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 2, 22)) +>X : Symbol(X, Decl(circularTypeArgumentsLocalAndOuterNoCrash1.ts, 3, 58)) +} + diff --git a/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.types b/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.types new file mode 100644 index 0000000000000..47ad9b521a015 --- /dev/null +++ b/tests/baselines/reference/circularTypeArgumentsLocalAndOuterNoCrash1.types @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts] //// + +=== circularTypeArgumentsLocalAndOuterNoCrash1.ts === +// https://github.com/microsoft/TypeScript/issues/59062 + +function f<_T, _S>() { +>f : <_T, _S>() => void +> : ^ ^^ ^^^^^^^^^^^ + + interface NumArray extends Array {} + type X = NumArray; +>X : NumArray +> : ^^^^^^^^^^^^^ +} + diff --git a/tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts b/tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts new file mode 100644 index 0000000000000..89ba056b8d2cf --- /dev/null +++ b/tests/cases/compiler/circularTypeArgumentsLocalAndOuterNoCrash1.ts @@ -0,0 +1,9 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/59062 + +function f<_T, _S>() { + interface NumArray extends Array {} + type X = NumArray; +}