From dac1da84343b76836f8eb60fddd5163e01ce170a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 20 Nov 2023 21:10:38 +0100 Subject: [PATCH] Add a test case for lack of duplicate property errors (#56348) --- ...eralProperty_computedNameNegative1.symbols | 47 +++++++++++++++ ...iteralProperty_computedNameNegative1.types | 59 +++++++++++++++++++ ...ctLiteralProperty_computedNameNegative1.ts | 19 ++++++ 3 files changed, 125 insertions(+) create mode 100644 tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.symbols create mode 100644 tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.types create mode 100644 tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.symbols b/tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.symbols new file mode 100644 index 00000000000..7d9e12106a7 --- /dev/null +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.symbols @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts] //// + +=== duplicateObjectLiteralProperty_computedNameNegative1.ts === +// repro from https://github.com/microsoft/TypeScript/issues/56341 + +function bar(props: { x?: string; y?: string }) { +>bar : Symbol(bar, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 0, 0)) +>props : Symbol(props, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 13)) +>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 21)) +>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 33)) + + const { x = "", y = "" } = props; +>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 9)) +>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 17)) +>props : Symbol(props, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 13)) + + return { + [x]: 1, +>[x] : Symbol([x], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 4, 10)) +>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 9)) + + [y]: 2, +>[y] : Symbol([y], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 5, 11)) +>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 17)) + + }; +} + +function foo({ x = "", y = "" }: { x?: string; y?: string }) { +>foo : Symbol(foo, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 8, 1)) +>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 14)) +>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 22)) +>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 34)) +>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 46)) + + return { + [x]: 1, +>[x] : Symbol([x], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 11, 10)) +>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 14)) + + [y]: 2, +>[y] : Symbol([y], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 12, 11)) +>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 22)) + + }; +} + diff --git a/tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.types b/tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.types new file mode 100644 index 00000000000..dcb52f928ee --- /dev/null +++ b/tests/baselines/reference/duplicateObjectLiteralProperty_computedNameNegative1.types @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts] //// + +=== duplicateObjectLiteralProperty_computedNameNegative1.ts === +// repro from https://github.com/microsoft/TypeScript/issues/56341 + +function bar(props: { x?: string; y?: string }) { +>bar : (props: { x?: string | undefined; y?: string | undefined; }) => { [x: string]: number; } +>props : { x?: string | undefined; y?: string | undefined; } +>x : string | undefined +>y : string | undefined + + const { x = "", y = "" } = props; +>x : string +>"" : "" +>y : string +>"" : "" +>props : { x?: string | undefined; y?: string | undefined; } + + return { +>{ [x]: 1, [y]: 2, } : { [x: string]: number; } + + [x]: 1, +>[x] : number +>x : string +>1 : 1 + + [y]: 2, +>[y] : number +>y : string +>2 : 2 + + }; +} + +function foo({ x = "", y = "" }: { x?: string; y?: string }) { +>foo : ({ x, y }: { x?: string; y?: string;}) => { [x: string]: number; } +>x : string +>"" : "" +>y : string +>"" : "" +>x : string | undefined +>y : string | undefined + + return { +>{ [x]: 1, [y]: 2, } : { [x: string]: number; } + + [x]: 1, +>[x] : number +>x : string +>1 : 1 + + [y]: 2, +>[y] : number +>y : string +>2 : 2 + + }; +} + diff --git a/tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts b/tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts new file mode 100644 index 00000000000..7c691bb0326 --- /dev/null +++ b/tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts @@ -0,0 +1,19 @@ +// @strict: true +// @noEmit: true + +// repro from https://github.com/microsoft/TypeScript/issues/56341 + +function bar(props: { x?: string; y?: string }) { + const { x = "", y = "" } = props; + return { + [x]: 1, + [y]: 2, + }; +} + +function foo({ x = "", y = "" }: { x?: string; y?: string }) { + return { + [x]: 1, + [y]: 2, + }; +}