Skip to content

Commit dac1da8

Browse files
authored
Add a test case for lack of duplicate property errors (#56348)
1 parent 9063d7b commit dac1da8

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts] ////
2+
3+
=== duplicateObjectLiteralProperty_computedNameNegative1.ts ===
4+
// repro from https://github.com/microsoft/TypeScript/issues/56341
5+
6+
function bar(props: { x?: string; y?: string }) {
7+
>bar : Symbol(bar, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 0, 0))
8+
>props : Symbol(props, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 13))
9+
>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 21))
10+
>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 33))
11+
12+
const { x = "", y = "" } = props;
13+
>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 9))
14+
>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 17))
15+
>props : Symbol(props, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 2, 13))
16+
17+
return {
18+
[x]: 1,
19+
>[x] : Symbol([x], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 4, 10))
20+
>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 9))
21+
22+
[y]: 2,
23+
>[y] : Symbol([y], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 5, 11))
24+
>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 3, 17))
25+
26+
};
27+
}
28+
29+
function foo({ x = "", y = "" }: { x?: string; y?: string }) {
30+
>foo : Symbol(foo, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 8, 1))
31+
>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 14))
32+
>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 22))
33+
>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 34))
34+
>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 46))
35+
36+
return {
37+
[x]: 1,
38+
>[x] : Symbol([x], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 11, 10))
39+
>x : Symbol(x, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 14))
40+
41+
[y]: 2,
42+
>[y] : Symbol([y], Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 12, 11))
43+
>y : Symbol(y, Decl(duplicateObjectLiteralProperty_computedNameNegative1.ts, 10, 22))
44+
45+
};
46+
}
47+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//// [tests/cases/compiler/duplicateObjectLiteralProperty_computedNameNegative1.ts] ////
2+
3+
=== duplicateObjectLiteralProperty_computedNameNegative1.ts ===
4+
// repro from https://github.com/microsoft/TypeScript/issues/56341
5+
6+
function bar(props: { x?: string; y?: string }) {
7+
>bar : (props: { x?: string | undefined; y?: string | undefined; }) => { [x: string]: number; }
8+
>props : { x?: string | undefined; y?: string | undefined; }
9+
>x : string | undefined
10+
>y : string | undefined
11+
12+
const { x = "", y = "" } = props;
13+
>x : string
14+
>"" : ""
15+
>y : string
16+
>"" : ""
17+
>props : { x?: string | undefined; y?: string | undefined; }
18+
19+
return {
20+
>{ [x]: 1, [y]: 2, } : { [x: string]: number; }
21+
22+
[x]: 1,
23+
>[x] : number
24+
>x : string
25+
>1 : 1
26+
27+
[y]: 2,
28+
>[y] : number
29+
>y : string
30+
>2 : 2
31+
32+
};
33+
}
34+
35+
function foo({ x = "", y = "" }: { x?: string; y?: string }) {
36+
>foo : ({ x, y }: { x?: string; y?: string;}) => { [x: string]: number; }
37+
>x : string
38+
>"" : ""
39+
>y : string
40+
>"" : ""
41+
>x : string | undefined
42+
>y : string | undefined
43+
44+
return {
45+
>{ [x]: 1, [y]: 2, } : { [x: string]: number; }
46+
47+
[x]: 1,
48+
>[x] : number
49+
>x : string
50+
>1 : 1
51+
52+
[y]: 2,
53+
>[y] : number
54+
>y : string
55+
>2 : 2
56+
57+
};
58+
}
59+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// repro from https://github.com/microsoft/TypeScript/issues/56341
5+
6+
function bar(props: { x?: string; y?: string }) {
7+
const { x = "", y = "" } = props;
8+
return {
9+
[x]: 1,
10+
[y]: 2,
11+
};
12+
}
13+
14+
function foo({ x = "", y = "" }: { x?: string; y?: string }) {
15+
return {
16+
[x]: 1,
17+
[y]: 2,
18+
};
19+
}

0 commit comments

Comments
 (0)