Skip to content

Commit 2938bbb

Browse files
committed
Test:keyof inference lower priority than return inference
for #22376
1 parent 27c171e commit 2938bbb

4 files changed

+387
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//// [keyofInferenceLowerPriorityThanReturn.ts]
2+
// #22736
3+
declare class Write {
4+
protected dummy: Write;
5+
}
6+
7+
declare class Col<s, a> {
8+
protected dummy: [Col<s, a>, s, a];
9+
}
10+
11+
declare class Table<Req, Def> {
12+
protected dummy: [Table<Req, Def>, Req, Def];
13+
}
14+
15+
type MakeTable<T1 extends object, T2 extends object> = {
16+
[P in keyof T1]: Col<Write, T1[P]>;
17+
} & {
18+
[P in keyof T2]: Col<Write, T2[P]>;
19+
};
20+
21+
declare class ConflictTarget<Cols> {
22+
public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>;
23+
protected dummy: [ConflictTarget<Cols>, Cols];
24+
}
25+
26+
27+
28+
const bookTable: Table<BookReq, BookDef> = null as any
29+
30+
interface BookReq {
31+
readonly title: string;
32+
readonly serial: number;
33+
}
34+
35+
interface BookDef {
36+
readonly author: string;
37+
readonly numPages: number | null;
38+
}
39+
40+
41+
function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
42+
throw new Error();
43+
}
44+
45+
function f() {
46+
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- Compile error here
47+
}
48+
49+
50+
//// [keyofInferenceLowerPriorityThanReturn.js]
51+
var bookTable = null;
52+
function insertOnConflictDoNothing(_table, _conflictTarget) {
53+
throw new Error();
54+
}
55+
function f() {
56+
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- Compile error here
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
=== tests/cases/compiler/keyofInferenceLowerPriorityThanReturn.ts ===
2+
// #22736
3+
declare class Write {
4+
>Write : Symbol(Write, Decl(keyofInferenceLowerPriorityThanReturn.ts, 0, 0))
5+
6+
protected dummy: Write;
7+
>dummy : Symbol(Write.dummy, Decl(keyofInferenceLowerPriorityThanReturn.ts, 1, 21))
8+
>Write : Symbol(Write, Decl(keyofInferenceLowerPriorityThanReturn.ts, 0, 0))
9+
}
10+
11+
declare class Col<s, a> {
12+
>Col : Symbol(Col, Decl(keyofInferenceLowerPriorityThanReturn.ts, 3, 1))
13+
>s : Symbol(s, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 18))
14+
>a : Symbol(a, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 20))
15+
16+
protected dummy: [Col<s, a>, s, a];
17+
>dummy : Symbol(Col.dummy, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 25))
18+
>Col : Symbol(Col, Decl(keyofInferenceLowerPriorityThanReturn.ts, 3, 1))
19+
>s : Symbol(s, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 18))
20+
>a : Symbol(a, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 20))
21+
>s : Symbol(s, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 18))
22+
>a : Symbol(a, Decl(keyofInferenceLowerPriorityThanReturn.ts, 5, 20))
23+
}
24+
25+
declare class Table<Req, Def> {
26+
>Table : Symbol(Table, Decl(keyofInferenceLowerPriorityThanReturn.ts, 7, 1))
27+
>Req : Symbol(Req, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 20))
28+
>Def : Symbol(Def, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 24))
29+
30+
protected dummy: [Table<Req, Def>, Req, Def];
31+
>dummy : Symbol(Table.dummy, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 31))
32+
>Table : Symbol(Table, Decl(keyofInferenceLowerPriorityThanReturn.ts, 7, 1))
33+
>Req : Symbol(Req, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 20))
34+
>Def : Symbol(Def, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 24))
35+
>Req : Symbol(Req, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 20))
36+
>Def : Symbol(Def, Decl(keyofInferenceLowerPriorityThanReturn.ts, 9, 24))
37+
}
38+
39+
type MakeTable<T1 extends object, T2 extends object> = {
40+
>MakeTable : Symbol(MakeTable, Decl(keyofInferenceLowerPriorityThanReturn.ts, 11, 1))
41+
>T1 : Symbol(T1, Decl(keyofInferenceLowerPriorityThanReturn.ts, 13, 15))
42+
>T2 : Symbol(T2, Decl(keyofInferenceLowerPriorityThanReturn.ts, 13, 33))
43+
44+
[P in keyof T1]: Col<Write, T1[P]>;
45+
>P : Symbol(P, Decl(keyofInferenceLowerPriorityThanReturn.ts, 14, 5))
46+
>T1 : Symbol(T1, Decl(keyofInferenceLowerPriorityThanReturn.ts, 13, 15))
47+
>Col : Symbol(Col, Decl(keyofInferenceLowerPriorityThanReturn.ts, 3, 1))
48+
>Write : Symbol(Write, Decl(keyofInferenceLowerPriorityThanReturn.ts, 0, 0))
49+
>T1 : Symbol(T1, Decl(keyofInferenceLowerPriorityThanReturn.ts, 13, 15))
50+
>P : Symbol(P, Decl(keyofInferenceLowerPriorityThanReturn.ts, 14, 5))
51+
52+
} & {
53+
[P in keyof T2]: Col<Write, T2[P]>;
54+
>P : Symbol(P, Decl(keyofInferenceLowerPriorityThanReturn.ts, 16, 9))
55+
>T2 : Symbol(T2, Decl(keyofInferenceLowerPriorityThanReturn.ts, 13, 33))
56+
>Col : Symbol(Col, Decl(keyofInferenceLowerPriorityThanReturn.ts, 3, 1))
57+
>Write : Symbol(Write, Decl(keyofInferenceLowerPriorityThanReturn.ts, 0, 0))
58+
>T2 : Symbol(T2, Decl(keyofInferenceLowerPriorityThanReturn.ts, 13, 33))
59+
>P : Symbol(P, Decl(keyofInferenceLowerPriorityThanReturn.ts, 16, 9))
60+
61+
};
62+
63+
declare class ConflictTarget<Cols> {
64+
>ConflictTarget : Symbol(ConflictTarget, Decl(keyofInferenceLowerPriorityThanReturn.ts, 17, 6))
65+
>Cols : Symbol(Cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 19, 29))
66+
67+
public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>;
68+
>tableColumns : Symbol(ConflictTarget.tableColumns, Decl(keyofInferenceLowerPriorityThanReturn.ts, 19, 36))
69+
>Cols : Symbol(Cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 20, 31))
70+
>cols : Symbol(cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 20, 37))
71+
>Cols : Symbol(Cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 20, 31))
72+
>ConflictTarget : Symbol(ConflictTarget, Decl(keyofInferenceLowerPriorityThanReturn.ts, 17, 6))
73+
>Cols : Symbol(Cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 20, 31))
74+
75+
protected dummy: [ConflictTarget<Cols>, Cols];
76+
>dummy : Symbol(ConflictTarget.dummy, Decl(keyofInferenceLowerPriorityThanReturn.ts, 20, 81))
77+
>ConflictTarget : Symbol(ConflictTarget, Decl(keyofInferenceLowerPriorityThanReturn.ts, 17, 6))
78+
>Cols : Symbol(Cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 19, 29))
79+
>Cols : Symbol(Cols, Decl(keyofInferenceLowerPriorityThanReturn.ts, 19, 29))
80+
}
81+
82+
83+
84+
const bookTable: Table<BookReq, BookDef> = null as any
85+
>bookTable : Symbol(bookTable, Decl(keyofInferenceLowerPriorityThanReturn.ts, 26, 5))
86+
>Table : Symbol(Table, Decl(keyofInferenceLowerPriorityThanReturn.ts, 7, 1))
87+
>BookReq : Symbol(BookReq, Decl(keyofInferenceLowerPriorityThanReturn.ts, 26, 54))
88+
>BookDef : Symbol(BookDef, Decl(keyofInferenceLowerPriorityThanReturn.ts, 31, 1))
89+
90+
interface BookReq {
91+
>BookReq : Symbol(BookReq, Decl(keyofInferenceLowerPriorityThanReturn.ts, 26, 54))
92+
93+
readonly title: string;
94+
>title : Symbol(BookReq.title, Decl(keyofInferenceLowerPriorityThanReturn.ts, 28, 19))
95+
96+
readonly serial: number;
97+
>serial : Symbol(BookReq.serial, Decl(keyofInferenceLowerPriorityThanReturn.ts, 29, 27))
98+
}
99+
100+
interface BookDef {
101+
>BookDef : Symbol(BookDef, Decl(keyofInferenceLowerPriorityThanReturn.ts, 31, 1))
102+
103+
readonly author: string;
104+
>author : Symbol(BookDef.author, Decl(keyofInferenceLowerPriorityThanReturn.ts, 33, 19))
105+
106+
readonly numPages: number | null;
107+
>numPages : Symbol(BookDef.numPages, Decl(keyofInferenceLowerPriorityThanReturn.ts, 34, 28))
108+
}
109+
110+
111+
function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
112+
>insertOnConflictDoNothing : Symbol(insertOnConflictDoNothing, Decl(keyofInferenceLowerPriorityThanReturn.ts, 36, 1))
113+
>Req : Symbol(Req, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 35))
114+
>Def : Symbol(Def, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 54))
115+
>_table : Symbol(_table, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 75))
116+
>Table : Symbol(Table, Decl(keyofInferenceLowerPriorityThanReturn.ts, 7, 1))
117+
>Req : Symbol(Req, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 35))
118+
>Def : Symbol(Def, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 54))
119+
>_conflictTarget : Symbol(_conflictTarget, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 99))
120+
>ConflictTarget : Symbol(ConflictTarget, Decl(keyofInferenceLowerPriorityThanReturn.ts, 17, 6))
121+
>Req : Symbol(Req, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 35))
122+
>Def : Symbol(Def, Decl(keyofInferenceLowerPriorityThanReturn.ts, 39, 54))
123+
124+
throw new Error();
125+
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
126+
}
127+
128+
function f() {
129+
>f : Symbol(f, Decl(keyofInferenceLowerPriorityThanReturn.ts, 41, 1))
130+
131+
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- Compile error here
132+
>insertOnConflictDoNothing : Symbol(insertOnConflictDoNothing, Decl(keyofInferenceLowerPriorityThanReturn.ts, 36, 1))
133+
>bookTable : Symbol(bookTable, Decl(keyofInferenceLowerPriorityThanReturn.ts, 26, 5))
134+
>ConflictTarget.tableColumns : Symbol(ConflictTarget.tableColumns, Decl(keyofInferenceLowerPriorityThanReturn.ts, 19, 36))
135+
>ConflictTarget : Symbol(ConflictTarget, Decl(keyofInferenceLowerPriorityThanReturn.ts, 17, 6))
136+
>tableColumns : Symbol(ConflictTarget.tableColumns, Decl(keyofInferenceLowerPriorityThanReturn.ts, 19, 36))
137+
}
138+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
=== tests/cases/compiler/keyofInferenceLowerPriorityThanReturn.ts ===
2+
// #22736
3+
declare class Write {
4+
>Write : Write
5+
6+
protected dummy: Write;
7+
>dummy : Write
8+
>Write : Write
9+
}
10+
11+
declare class Col<s, a> {
12+
>Col : Col<s, a>
13+
>s : s
14+
>a : a
15+
16+
protected dummy: [Col<s, a>, s, a];
17+
>dummy : [Col<s, a>, s, a]
18+
>Col : Col<s, a>
19+
>s : s
20+
>a : a
21+
>s : s
22+
>a : a
23+
}
24+
25+
declare class Table<Req, Def> {
26+
>Table : Table<Req, Def>
27+
>Req : Req
28+
>Def : Def
29+
30+
protected dummy: [Table<Req, Def>, Req, Def];
31+
>dummy : [Table<Req, Def>, Req, Def]
32+
>Table : Table<Req, Def>
33+
>Req : Req
34+
>Def : Def
35+
>Req : Req
36+
>Def : Def
37+
}
38+
39+
type MakeTable<T1 extends object, T2 extends object> = {
40+
>MakeTable : MakeTable<T1, T2>
41+
>T1 : T1
42+
>T2 : T2
43+
44+
[P in keyof T1]: Col<Write, T1[P]>;
45+
>P : P
46+
>T1 : T1
47+
>Col : Col<s, a>
48+
>Write : Write
49+
>T1 : T1
50+
>P : P
51+
52+
} & {
53+
[P in keyof T2]: Col<Write, T2[P]>;
54+
>P : P
55+
>T2 : T2
56+
>Col : Col<s, a>
57+
>Write : Write
58+
>T2 : T2
59+
>P : P
60+
61+
};
62+
63+
declare class ConflictTarget<Cols> {
64+
>ConflictTarget : ConflictTarget<Cols>
65+
>Cols : Cols
66+
67+
public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>;
68+
>tableColumns : <Cols>(cols: (keyof Cols)[]) => ConflictTarget<Cols>
69+
>Cols : Cols
70+
>cols : (keyof Cols)[]
71+
>Cols : Cols
72+
>ConflictTarget : ConflictTarget<Cols>
73+
>Cols : Cols
74+
75+
protected dummy: [ConflictTarget<Cols>, Cols];
76+
>dummy : [ConflictTarget<Cols>, Cols]
77+
>ConflictTarget : ConflictTarget<Cols>
78+
>Cols : Cols
79+
>Cols : Cols
80+
}
81+
82+
83+
84+
const bookTable: Table<BookReq, BookDef> = null as any
85+
>bookTable : Table<BookReq, BookDef>
86+
>Table : Table<Req, Def>
87+
>BookReq : BookReq
88+
>BookDef : BookDef
89+
>null as any : any
90+
>null : null
91+
92+
interface BookReq {
93+
>BookReq : BookReq
94+
95+
readonly title: string;
96+
>title : string
97+
98+
readonly serial: number;
99+
>serial : number
100+
}
101+
102+
interface BookDef {
103+
>BookDef : BookDef
104+
105+
readonly author: string;
106+
>author : string
107+
108+
readonly numPages: number | null;
109+
>numPages : number
110+
>null : null
111+
}
112+
113+
114+
function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
115+
>insertOnConflictDoNothing : <Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>) => boolean
116+
>Req : Req
117+
>Def : Def
118+
>_table : Table<Req, Def>
119+
>Table : Table<Req, Def>
120+
>Req : Req
121+
>Def : Def
122+
>_conflictTarget : ConflictTarget<Req & Def>
123+
>ConflictTarget : ConflictTarget<Cols>
124+
>Req : Req
125+
>Def : Def
126+
127+
throw new Error();
128+
>new Error() : Error
129+
>Error : ErrorConstructor
130+
}
131+
132+
function f() {
133+
>f : () => void
134+
135+
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- Compile error here
136+
>insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])) : boolean
137+
>insertOnConflictDoNothing : <Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>) => boolean
138+
>bookTable : Table<BookReq, BookDef>
139+
>ConflictTarget.tableColumns(["serial"]) : ConflictTarget<BookReq & BookDef>
140+
>ConflictTarget.tableColumns : <Cols>(cols: (keyof Cols)[]) => ConflictTarget<Cols>
141+
>ConflictTarget : typeof ConflictTarget
142+
>tableColumns : <Cols>(cols: (keyof Cols)[]) => ConflictTarget<Cols>
143+
>["serial"] : "serial"[]
144+
>"serial" : "serial"
145+
}
146+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// #22736
2+
declare class Write {
3+
protected dummy: Write;
4+
}
5+
6+
declare class Col<s, a> {
7+
protected dummy: [Col<s, a>, s, a];
8+
}
9+
10+
declare class Table<Req, Def> {
11+
protected dummy: [Table<Req, Def>, Req, Def];
12+
}
13+
14+
type MakeTable<T1 extends object, T2 extends object> = {
15+
[P in keyof T1]: Col<Write, T1[P]>;
16+
} & {
17+
[P in keyof T2]: Col<Write, T2[P]>;
18+
};
19+
20+
declare class ConflictTarget<Cols> {
21+
public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>;
22+
protected dummy: [ConflictTarget<Cols>, Cols];
23+
}
24+
25+
26+
27+
const bookTable: Table<BookReq, BookDef> = null as any
28+
29+
interface BookReq {
30+
readonly title: string;
31+
readonly serial: number;
32+
}
33+
34+
interface BookDef {
35+
readonly author: string;
36+
readonly numPages: number | null;
37+
}
38+
39+
40+
function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
41+
throw new Error();
42+
}
43+
44+
function f() {
45+
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- Compile error here
46+
}

0 commit comments

Comments
 (0)