diff --git a/src/compiler/expressionToTypeNode.ts b/src/compiler/expressionToTypeNode.ts index ad4f8321066e9..d754947177c52 100644 --- a/src/compiler/expressionToTypeNode.ts +++ b/src/compiler/expressionToTypeNode.ts @@ -1123,15 +1123,16 @@ export function createSyntacticTypeNodeBuilder( ); } function reuseTypeParameters(typeParameters: NodeArray | undefined, context: SyntacticTypeNodeBuilderContext) { - return typeParameters?.map(tp => - factory.updateTypeParameterDeclaration( + return typeParameters?.map(tp => { + const { node: tpName } = resolver.trackExistingEntityName(context, tp.name); + return factory.updateTypeParameterDeclaration( tp, tp.modifiers?.map(m => reuseNode(context, m)), - reuseNode(context, tp.name), + tpName, serializeExistingTypeNodeWithFallback(tp.constraint, context), serializeExistingTypeNodeWithFallback(tp.default, context), - ) - ); + ); + }); } function typeFromObjectLiteralMethod(method: MethodDeclaration, name: PropertyName, context: SyntacticTypeNodeBuilderContext, isConstContext: boolean) { diff --git a/tests/baselines/reference/declarationEmitShadowing.js b/tests/baselines/reference/declarationEmitShadowing.js new file mode 100644 index 0000000000000..e3ec2b61204d4 --- /dev/null +++ b/tests/baselines/reference/declarationEmitShadowing.js @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/declarationEmitShadowing.ts] //// + +//// [declarationEmitShadowing.ts] +export class A { + public readonly ShadowedButDoesNotRequireRenaming = (): T => { + return null as any + } +} + +export function needsRenameForShadowing() { + type A = T + return function O(t: A, t2: T) { + } +} + + +//// [declarationEmitShadowing.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.A = void 0; +exports.needsRenameForShadowing = needsRenameForShadowing; +var A = /** @class */ (function () { + function A() { + this.ShadowedButDoesNotRequireRenaming = function () { + return null; + }; + } + return A; +}()); +exports.A = A; +function needsRenameForShadowing() { + return function O(t, t2) { + }; +} + + +//// [declarationEmitShadowing.d.ts] +export declare class A { + readonly ShadowedButDoesNotRequireRenaming: () => T_1; +} +export declare function needsRenameForShadowing(): (t: T, t2: T_1) => void; diff --git a/tests/baselines/reference/declarationEmitShadowing.symbols b/tests/baselines/reference/declarationEmitShadowing.symbols new file mode 100644 index 0000000000000..06f127f02fa72 --- /dev/null +++ b/tests/baselines/reference/declarationEmitShadowing.symbols @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/declarationEmitShadowing.ts] //// + +=== declarationEmitShadowing.ts === +export class A { +>A : Symbol(A, Decl(declarationEmitShadowing.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 0, 15)) + + public readonly ShadowedButDoesNotRequireRenaming = (): T => { +>ShadowedButDoesNotRequireRenaming : Symbol(A.ShadowedButDoesNotRequireRenaming, Decl(declarationEmitShadowing.ts, 0, 25)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 1, 55)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 1, 55)) + + return null as any + } +} + +export function needsRenameForShadowing() { +>needsRenameForShadowing : Symbol(needsRenameForShadowing, Decl(declarationEmitShadowing.ts, 4, 1)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 6, 40)) + + type A = T +>A : Symbol(A, Decl(declarationEmitShadowing.ts, 6, 46)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 6, 40)) + + return function O(t: A, t2: T) { +>O : Symbol(O, Decl(declarationEmitShadowing.ts, 8, 8)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 8, 20)) +>t : Symbol(t, Decl(declarationEmitShadowing.ts, 8, 23)) +>A : Symbol(A, Decl(declarationEmitShadowing.ts, 6, 46)) +>t2 : Symbol(t2, Decl(declarationEmitShadowing.ts, 8, 28)) +>T : Symbol(T, Decl(declarationEmitShadowing.ts, 8, 20)) + } +} + diff --git a/tests/baselines/reference/declarationEmitShadowing.types b/tests/baselines/reference/declarationEmitShadowing.types new file mode 100644 index 0000000000000..014d0569cfe30 --- /dev/null +++ b/tests/baselines/reference/declarationEmitShadowing.types @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/declarationEmitShadowing.ts] //// + +=== declarationEmitShadowing.ts === +export class A { +>A : A +> : ^^^^ + + public readonly ShadowedButDoesNotRequireRenaming = (): T => { +>ShadowedButDoesNotRequireRenaming : () => T_1 +> : ^^^^^^^^^^^ +>(): T => { return null as any } : () => T_1 +> : ^^^^^^^^^^^ + + return null as any +>null as any : any + } +} + +export function needsRenameForShadowing() { +>needsRenameForShadowing : () => (t: T, t2: T_1) => void +> : ^ ^^^^^^^^ ^^ ^^^ ^^^^^^^^^ + + type A = T +>A : T +> : ^ + + return function O(t: A, t2: T) { +>function O(t: A, t2: T) { } : (t: T, t2: T_1) => void +> : ^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>O : (t: T_1, t2: T) => void +> : ^ ^^ ^^^^^^^ ^^ ^^^^^^^^^ +>t : T_1 +> : ^^^ +>t2 : T +> : ^ + } +} + diff --git a/tests/cases/compiler/declarationEmitShadowing.ts b/tests/cases/compiler/declarationEmitShadowing.ts new file mode 100644 index 0000000000000..53c00fbc455a9 --- /dev/null +++ b/tests/cases/compiler/declarationEmitShadowing.ts @@ -0,0 +1,13 @@ +// @declaration: true + +export class A { + public readonly ShadowedButDoesNotRequireRenaming = (): T => { + return null as any + } +} + +export function needsRenameForShadowing() { + type A = T + return function O(t: A, t2: T) { + } +}