Skip to content

Commit 42c17e1

Browse files
committed
Address PR comments
1 parent 5138e8b commit 42c17e1

9 files changed

+149
-53
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,12 +6036,10 @@ namespace ts {
60366036
const resolved = resolveStructuredTypeMembers(type);
60376037
if ((relation === assignableRelation || relation === comparableRelation) && (type === globalObjectType || isEmptyObjectType(resolved)) ||
60386038
resolved.stringIndexInfo ||
6039+
(resolved.numberIndexInfo && isNumericLiteralName(name)) ||
60396040
getPropertyOfType(type, name)) {
60406041
return true;
60416042
}
6042-
if (resolved.numberIndexInfo) {
6043-
return isNumericLiteralName(name);
6044-
}
60456043
}
60466044
else if (type.flags & TypeFlags.UnionOrIntersection) {
60476045
for (const t of (<UnionOrIntersectionType>type).types) {
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
//// [computedPropertyNamesContextualType7_ES5.ts]
22
interface I<T> {
3-
[s: number]: T;
3+
[n: number]: T;
4+
}
5+
interface J<T> {
6+
[s: string]: T;
47
}
58

6-
declare function foo<T>(obj: I<T>): T
9+
declare function foo<T>(obj: I<T>): T;
10+
declare function g<T>(obj: J<T>): T;
711

812
foo({
9-
101: "",
1013
0: () => { },
1114
["hi" + "bye"]: true,
1215
[0 + 1]: 0,
1316
[+"hi"]: [0]
1417
});
18+
19+
g({ p: "" });
1520

1621

1722
//// [computedPropertyNamesContextualType7_ES5.js]
1823
foo((_a = {
19-
101: "",
2024
0: function () { }
2125
},
2226
_a["hi" + "bye"] = true,
2327
_a[0 + 1] = 0,
2428
_a[+"hi"] = [0],
2529
_a
2630
));
31+
g({ p: "" });
2732
var _a;

tests/baselines/reference/computedPropertyNamesContextualType7_ES5.symbols

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,45 @@ interface I<T> {
33
>I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 0))
44
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 12))
55

6-
[s: number]: T;
7-
>s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES5.ts, 1, 5))
6+
[n: number]: T;
7+
>n : Symbol(n, Decl(computedPropertyNamesContextualType7_ES5.ts, 1, 5))
88
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 12))
99
}
10+
interface J<T> {
11+
>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1))
12+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 3, 12))
1013

11-
declare function foo<T>(obj: I<T>): T
12-
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1))
13-
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 21))
14-
>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 24))
14+
[s: string]: T;
15+
>s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 5))
16+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 3, 12))
17+
}
18+
19+
declare function foo<T>(obj: I<T>): T;
20+
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 5, 1))
21+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 21))
22+
>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 24))
1523
>I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES5.ts, 0, 0))
16-
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 21))
17-
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 4, 21))
24+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 21))
25+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 21))
26+
27+
declare function g<T>(obj: J<T>): T;
28+
>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 38))
29+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 19))
30+
>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 22))
31+
>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1))
32+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 19))
33+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES5.ts, 8, 19))
1834

1935
foo({
20-
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 2, 1))
36+
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES5.ts, 5, 1))
2137

22-
101: "",
2338
0: () => { },
2439
["hi" + "bye"]: true,
2540
[0 + 1]: 0,
2641
[+"hi"]: [0]
2742
});
2843

44+
g({ p: "" });
45+
>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES5.ts, 7, 38))
46+
>p : Symbol(p, Decl(computedPropertyNamesContextualType7_ES5.ts, 17, 3))
47+

tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,39 @@ interface I<T> {
33
>I : I<T>
44
>T : T
55

6-
[s: number]: T;
7-
>s : number
6+
[n: number]: T;
7+
>n : number
8+
>T : T
9+
}
10+
interface J<T> {
11+
>J : J<T>
12+
>T : T
13+
14+
[s: string]: T;
15+
>s : string
816
>T : T
917
}
1018

11-
declare function foo<T>(obj: I<T>): T
19+
declare function foo<T>(obj: I<T>): T;
1220
>foo : <T>(obj: I<T>) => T
1321
>T : T
1422
>obj : I<T>
1523
>I : I<T>
1624
>T : T
1725
>T : T
1826

27+
declare function g<T>(obj: J<T>): T;
28+
>g : <T>(obj: J<T>) => T
29+
>T : T
30+
>obj : J<T>
31+
>J : J<T>
32+
>T : T
33+
>T : T
34+
1935
foo({
20-
>foo({ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | number | number[]
36+
>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[]
2137
>foo : <T>(obj: I<T>) => T
22-
>{ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: string | (() => void) | number | number[]; 0: () => void; 101: string; }
23-
24-
101: "",
25-
>"" : string
38+
>{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; }
2639

2740
0: () => { },
2841
>() => { } : () => void
@@ -47,3 +60,10 @@ foo({
4760

4861
});
4962

63+
g({ p: "" });
64+
>g({ p: "" }) : string
65+
>g : <T>(obj: J<T>) => T
66+
>{ p: "" } : { p: string; }
67+
>p : string
68+
>"" : string
69+
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
//// [computedPropertyNamesContextualType7_ES6.ts]
22
interface I<T> {
3-
[s: number]: T;
3+
[n: number]: T;
4+
}
5+
interface J<T> {
6+
[s: string]: T;
47
}
58

6-
declare function foo<T>(obj: I<T>): T
9+
declare function foo<T>(obj: I<T>): T;
10+
declare function g<T>(obj: J<T>): T;
711

812
foo({
9-
101: "",
1013
0: () => { },
1114
["hi" + "bye"]: true,
1215
[0 + 1]: 0,
1316
[+"hi"]: [0]
1417
});
18+
19+
g({ p: "" });
1520

1621

1722
//// [computedPropertyNamesContextualType7_ES6.js]
1823
foo({
19-
101: "",
2024
0: () => { },
2125
["hi" + "bye"]: true,
2226
[0 + 1]: 0,
2327
[+"hi"]: [0]
2428
});
29+
g({ p: "" });

tests/baselines/reference/computedPropertyNamesContextualType7_ES6.symbols

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,45 @@ interface I<T> {
33
>I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 0))
44
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 12))
55

6-
[s: number]: T;
7-
>s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES6.ts, 1, 5))
6+
[n: number]: T;
7+
>n : Symbol(n, Decl(computedPropertyNamesContextualType7_ES6.ts, 1, 5))
88
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 12))
99
}
10+
interface J<T> {
11+
>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1))
12+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 3, 12))
1013

11-
declare function foo<T>(obj: I<T>): T
12-
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1))
13-
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 21))
14-
>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 24))
14+
[s: string]: T;
15+
>s : Symbol(s, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 5))
16+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 3, 12))
17+
}
18+
19+
declare function foo<T>(obj: I<T>): T;
20+
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 5, 1))
21+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 21))
22+
>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 24))
1523
>I : Symbol(I, Decl(computedPropertyNamesContextualType7_ES6.ts, 0, 0))
16-
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 21))
17-
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 4, 21))
24+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 21))
25+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 21))
26+
27+
declare function g<T>(obj: J<T>): T;
28+
>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 38))
29+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 19))
30+
>obj : Symbol(obj, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 22))
31+
>J : Symbol(J, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1))
32+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 19))
33+
>T : Symbol(T, Decl(computedPropertyNamesContextualType7_ES6.ts, 8, 19))
1834

1935
foo({
20-
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 2, 1))
36+
>foo : Symbol(foo, Decl(computedPropertyNamesContextualType7_ES6.ts, 5, 1))
2137

22-
101: "",
2338
0: () => { },
2439
["hi" + "bye"]: true,
2540
[0 + 1]: 0,
2641
[+"hi"]: [0]
2742
});
2843

44+
g({ p: "" });
45+
>g : Symbol(g, Decl(computedPropertyNamesContextualType7_ES6.ts, 7, 38))
46+
>p : Symbol(p, Decl(computedPropertyNamesContextualType7_ES6.ts, 17, 3))
47+

tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,39 @@ interface I<T> {
33
>I : I<T>
44
>T : T
55

6-
[s: number]: T;
7-
>s : number
6+
[n: number]: T;
7+
>n : number
8+
>T : T
9+
}
10+
interface J<T> {
11+
>J : J<T>
12+
>T : T
13+
14+
[s: string]: T;
15+
>s : string
816
>T : T
917
}
1018

11-
declare function foo<T>(obj: I<T>): T
19+
declare function foo<T>(obj: I<T>): T;
1220
>foo : <T>(obj: I<T>) => T
1321
>T : T
1422
>obj : I<T>
1523
>I : I<T>
1624
>T : T
1725
>T : T
1826

27+
declare function g<T>(obj: J<T>): T;
28+
>g : <T>(obj: J<T>) => T
29+
>T : T
30+
>obj : J<T>
31+
>J : J<T>
32+
>T : T
33+
>T : T
34+
1935
foo({
20-
>foo({ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | number | number[]
36+
>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[]
2137
>foo : <T>(obj: I<T>) => T
22-
>{ 101: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | (() => void) | boolean | number | number[]; [x: number]: string | (() => void) | number | number[]; 0: () => void; 101: string; }
23-
24-
101: "",
25-
>"" : string
38+
>{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; }
2639

2740
0: () => { },
2841
>() => { } : () => void
@@ -47,3 +60,10 @@ foo({
4760

4861
});
4962

63+
g({ p: "" });
64+
>g({ p: "" }) : string
65+
>g : <T>(obj: J<T>) => T
66+
>{ p: "" } : { p: string; }
67+
>p : string
68+
>"" : string
69+
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// @target: es5
22
interface I<T> {
3-
[s: number]: T;
3+
[n: number]: T;
4+
}
5+
interface J<T> {
6+
[s: string]: T;
47
}
58

6-
declare function foo<T>(obj: I<T>): T
9+
declare function foo<T>(obj: I<T>): T;
10+
declare function g<T>(obj: J<T>): T;
711

812
foo({
9-
101: "",
1013
0: () => { },
1114
["hi" + "bye"]: true,
1215
[0 + 1]: 0,
1316
[+"hi"]: [0]
1417
});
18+
19+
g({ p: "" });
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// @target: es6
22
interface I<T> {
3-
[s: number]: T;
3+
[n: number]: T;
4+
}
5+
interface J<T> {
6+
[s: string]: T;
47
}
58

6-
declare function foo<T>(obj: I<T>): T
9+
declare function foo<T>(obj: I<T>): T;
10+
declare function g<T>(obj: J<T>): T;
711

812
foo({
9-
101: "",
1013
0: () => { },
1114
["hi" + "bye"]: true,
1215
[0 + 1]: 0,
1316
[+"hi"]: [0]
1417
});
18+
19+
g({ p: "" });

0 commit comments

Comments
 (0)