Add a test case for lack of duplicate property errors (#56348)

This commit is contained in:
Mateusz Burzyński 2023-11-20 21:10:38 +01:00 committed by GitHub
parent 9063d7b41d
commit dac1da8434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 125 additions and 0 deletions

View File

@ -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))
};
}

View File

@ -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
};
}

View File

@ -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,
};
}