-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
The following code works great in these TypeScript versions:
- 2.4.2
- 2.5.3
- 2.6.1
- 2.6.2
But it gives a compile error in these TypeScript versions:
- 2.7.1
- 2.7.2
- 2.8.0-dev.20180307
BugTest.ts
class Write {
protected dummy: Write;
}
class Col<s, a> {
protected dummy: [Col<s, a>, s, a];
}
class Table<Req, Def> {
protected dummy: [Table<Req, Def>, Req, Def];
}
type MakeTable<T1 extends object, T2 extends object> = {
[P in keyof T1]: Col<Write, T1[P]>;
} & {
[P in keyof T2]: Col<Write, T2[P]>;
};
class ConflictTarget<Cols> {
public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols> {
return <any>{
tableCols: cols.slice()
};
}
protected dummy: [ConflictTarget<Cols>, Cols];
}
const bookTable: Table<BookReq, BookDef> = null as any
interface BookReq {
readonly title: string;
readonly serial: number;
}
interface BookDef {
readonly author: string;
readonly numPages: number | null;
}
function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean {
throw new Error();
}
function f() {
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- Compile error here
}
BugTest.ts(49,42): error TS2345: Argument of type 'ConflictTarget<{ serial: any; }>' is not assignable to parameter of type 'ConflictTarget<BookReq & BookDef>'.
Type '{ serial: any; }' is not assignable to type 'BookReq & BookDef'.
Type '{ serial: any; }' is not assignable to type 'BookReq'.
Property 'title' is missing in type '{ serial: any; }'.
Manually adding the type argument allows the compile to succeed:
insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns<BookReq & BookDef>(["serial"]));
atMari
Metadata
Metadata
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue