diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 770e1a7c1c6..0b7c0fae1cf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8836,7 +8836,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ); } if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName && !isLateBindableName(node.name)) { - if (!(context.flags & NodeBuilderFlags.AllowUnresolvedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) { + if (!hasDynamicName(node)) { + return visitEachChild(node, visitExistingNodeTreeSymbols); + } + if (!(context.flags & NodeBuilderFlags.AllowUnresolvedNames && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) { return undefined; } } diff --git a/tests/baselines/reference/declarationEmitComputedPropertyName1.js b/tests/baselines/reference/declarationEmitComputedPropertyName1.js new file mode 100644 index 00000000000..511ff192635 --- /dev/null +++ b/tests/baselines/reference/declarationEmitComputedPropertyName1.js @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/declarationEmitComputedPropertyName1.ts] //// + +//// [declarationEmitComputedPropertyName1.ts] +// https://github.com/microsoft/TypeScript/issues/59107 + +declare function create(): T; + +export const c = create<{ + data: { + ["a_b_c"]: string; + ["sss"]: string; + s_d: string; + queryData?: string; + ["foo bar"]: string; + }; + ["a_b_c"]: string; +}>(); + +export interface IData { + ["a_b_c"]: string; + nested: { + ["d_e_f"]: string; + value: string; + ["qwe rty"]: string; + }; +} + + + + +//// [declarationEmitComputedPropertyName1.d.ts] +export declare const c: { + data: { + ["a_b_c"]: string; + ["sss"]: string; + s_d: string; + queryData?: string; + ["foo bar"]: string; + }; + a_b_c: string; +}; +export interface IData { + ["a_b_c"]: string; + nested: { + ["d_e_f"]: string; + value: string; + ["qwe rty"]: string; + }; +} diff --git a/tests/baselines/reference/declarationEmitComputedPropertyName1.symbols b/tests/baselines/reference/declarationEmitComputedPropertyName1.symbols new file mode 100644 index 00000000000..eb35605942e --- /dev/null +++ b/tests/baselines/reference/declarationEmitComputedPropertyName1.symbols @@ -0,0 +1,66 @@ +//// [tests/cases/compiler/declarationEmitComputedPropertyName1.ts] //// + +=== declarationEmitComputedPropertyName1.ts === +// https://github.com/microsoft/TypeScript/issues/59107 + +declare function create(): T; +>create : Symbol(create, Decl(declarationEmitComputedPropertyName1.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitComputedPropertyName1.ts, 2, 24)) +>T : Symbol(T, Decl(declarationEmitComputedPropertyName1.ts, 2, 24)) + +export const c = create<{ +>c : Symbol(c, Decl(declarationEmitComputedPropertyName1.ts, 4, 12)) +>create : Symbol(create, Decl(declarationEmitComputedPropertyName1.ts, 0, 0)) + + data: { +>data : Symbol(data, Decl(declarationEmitComputedPropertyName1.ts, 4, 25)) + + ["a_b_c"]: string; +>["a_b_c"] : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 5, 9)) +>"a_b_c" : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 5, 9)) + + ["sss"]: string; +>["sss"] : Symbol(["sss"], Decl(declarationEmitComputedPropertyName1.ts, 6, 22)) +>"sss" : Symbol(["sss"], Decl(declarationEmitComputedPropertyName1.ts, 6, 22)) + + s_d: string; +>s_d : Symbol(s_d, Decl(declarationEmitComputedPropertyName1.ts, 7, 20)) + + queryData?: string; +>queryData : Symbol(queryData, Decl(declarationEmitComputedPropertyName1.ts, 8, 16)) + + ["foo bar"]: string; +>["foo bar"] : Symbol(["foo bar"], Decl(declarationEmitComputedPropertyName1.ts, 9, 23)) +>"foo bar" : Symbol(["foo bar"], Decl(declarationEmitComputedPropertyName1.ts, 9, 23)) + + }; + ["a_b_c"]: string; +>["a_b_c"] : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 11, 4)) +>"a_b_c" : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 11, 4)) + +}>(); + +export interface IData { +>IData : Symbol(IData, Decl(declarationEmitComputedPropertyName1.ts, 13, 5)) + + ["a_b_c"]: string; +>["a_b_c"] : Symbol(IData["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 15, 24)) +>"a_b_c" : Symbol(IData["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 15, 24)) + + nested: { +>nested : Symbol(IData.nested, Decl(declarationEmitComputedPropertyName1.ts, 16, 20)) + + ["d_e_f"]: string; +>["d_e_f"] : Symbol(["d_e_f"], Decl(declarationEmitComputedPropertyName1.ts, 17, 11)) +>"d_e_f" : Symbol(["d_e_f"], Decl(declarationEmitComputedPropertyName1.ts, 17, 11)) + + value: string; +>value : Symbol(value, Decl(declarationEmitComputedPropertyName1.ts, 18, 22)) + + ["qwe rty"]: string; +>["qwe rty"] : Symbol(["qwe rty"], Decl(declarationEmitComputedPropertyName1.ts, 19, 18)) +>"qwe rty" : Symbol(["qwe rty"], Decl(declarationEmitComputedPropertyName1.ts, 19, 18)) + + }; +} + diff --git a/tests/baselines/reference/declarationEmitComputedPropertyName1.types b/tests/baselines/reference/declarationEmitComputedPropertyName1.types new file mode 100644 index 00000000000..e4c9a589448 --- /dev/null +++ b/tests/baselines/reference/declarationEmitComputedPropertyName1.types @@ -0,0 +1,86 @@ +//// [tests/cases/compiler/declarationEmitComputedPropertyName1.ts] //// + +=== declarationEmitComputedPropertyName1.ts === +// https://github.com/microsoft/TypeScript/issues/59107 + +declare function create(): T; +>create : () => T +> : ^ ^^^^^^^^^ ^^^^^^^ + +export const c = create<{ +>c : { data: { ["a_b_c"]: string; ["sss"]: string; s_d: string; queryData?: string; ["foo bar"]: string; }; a_b_c: string; } +> : ^^^^^^^^ ^^^^^^^^^ ^^^ +>create<{ data: { ["a_b_c"]: string; ["sss"]: string; s_d: string; queryData?: string; ["foo bar"]: string; }; ["a_b_c"]: string;}>() : { data: { ["a_b_c"]: string; ["sss"]: string; s_d: string; queryData?: string; ["foo bar"]: string; }; a_b_c: string; } +> : ^^^^^^^^ ^^^^^^^^^ ^^^ +>create : () => T +> : ^ ^^^^^^^^^ ^^^^^^^ + + data: { +>data : { a_b_c: string; sss: string; s_d: string; queryData?: string; "foo bar": string; } +> : ^^^^^^^^^ ^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^ + + ["a_b_c"]: string; +>["a_b_c"] : string +> : ^^^^^^ +>"a_b_c" : "a_b_c" +> : ^^^^^^^ + + ["sss"]: string; +>["sss"] : string +> : ^^^^^^ +>"sss" : "sss" +> : ^^^^^ + + s_d: string; +>s_d : string +> : ^^^^^^ + + queryData?: string; +>queryData : string | undefined +> : ^^^^^^^^^^^^^^^^^^ + + ["foo bar"]: string; +>["foo bar"] : string +> : ^^^^^^ +>"foo bar" : "foo bar" +> : ^^^^^^^^^ + + }; + ["a_b_c"]: string; +>["a_b_c"] : string +> : ^^^^^^ +>"a_b_c" : "a_b_c" +> : ^^^^^^^ + +}>(); + +export interface IData { + ["a_b_c"]: string; +>["a_b_c"] : string +> : ^^^^^^ +>"a_b_c" : "a_b_c" +> : ^^^^^^^ + + nested: { +>nested : { d_e_f: string; value: string; "qwe rty": string; } +> : ^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^ + + ["d_e_f"]: string; +>["d_e_f"] : string +> : ^^^^^^ +>"d_e_f" : "d_e_f" +> : ^^^^^^^ + + value: string; +>value : string +> : ^^^^^^ + + ["qwe rty"]: string; +>["qwe rty"] : string +> : ^^^^^^ +>"qwe rty" : "qwe rty" +> : ^^^^^^^^^ + + }; +} + diff --git a/tests/cases/compiler/declarationEmitComputedPropertyName1.ts b/tests/cases/compiler/declarationEmitComputedPropertyName1.ts new file mode 100644 index 00000000000..2ffc206f8f7 --- /dev/null +++ b/tests/cases/compiler/declarationEmitComputedPropertyName1.ts @@ -0,0 +1,27 @@ +// @strict: true +// @declaration: true +// @emitDeclarationOnly: true + +// https://github.com/microsoft/TypeScript/issues/59107 + +declare function create(): T; + +export const c = create<{ + data: { + ["a_b_c"]: string; + ["sss"]: string; + s_d: string; + queryData?: string; + ["foo bar"]: string; + }; + ["a_b_c"]: string; +}>(); + +export interface IData { + ["a_b_c"]: string; + nested: { + ["d_e_f"]: string; + value: string; + ["qwe rty"]: string; + }; +}