• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//// [keyofInferenceLowerPriorityThanReturn.ts]
2// #22736
3declare class Write {
4    protected dummy: Write;
5}
6
7declare class Col<s, a> {
8    protected dummy: [Col<s, a>, s, a];
9}
10
11declare class Table<Req, Def> {
12    protected dummy: [Table<Req, Def>, Req, Def];
13}
14
15type 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
21declare class ConflictTarget<Cols> {
22    public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>;
23    protected dummy: [ConflictTarget<Cols>, Cols];
24}
25
26
27
28const bookTable: Table<BookReq, BookDef> = null as any
29
30interface BookReq {
31    readonly title: string;
32    readonly serial: number;
33}
34
35interface BookDef {
36    readonly author: string;
37    readonly numPages: number | null;
38}
39
40
41function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
42    throw new Error();
43}
44
45function f() {
46    insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"]));  // <-- No error here; should use the type inferred for the return type of `tableColumns`
47}
48
49
50//// [keyofInferenceLowerPriorityThanReturn.js]
51var bookTable = null;
52function insertOnConflictDoNothing(_table, _conflictTarget) {
53    throw new Error();
54}
55function f() {
56    insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- No error here; should use the type inferred for the return type of `tableColumns`
57}
58