-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Intersection of empty object type with empty object type is missing index signature #20225
Copy link
Copy link
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: 2.7.0-dev.20171122
Code
type Dictionary = { [name: string]: string };
const intersectDictionaries = <F1 extends Dictionary, F2 extends Dictionary>(
d1: F1,
d2: F2,
): F1 & F2 => Object.assign({}, d1, d2);
const testDictionary = <T extends Dictionary>(_value: T) => { };
const d1 = {};
testDictionary(d1); // OK, d1 is inferred to be {}
const d2 = intersectDictionaries(d1, d1);
testDictionary(d2); // error, d2 is inferred to be {}
// compile error on the above line:
// ts-braces-not-assignable.ts(13,16): error TS2345: Argument of type '{}'
// is not assignable to parameter of type 'Dictionary'.
// Index signature is missing in type '{}'.
const d3 = {
s: '',
};
testDictionary(d3); // OK
const d4 = intersectDictionaries(d1, d3);
testDictionary(d4); // OK
const d5 = intersectDictionaries(d3, d1);
testDictionary(d5); // OK
const d6 = intersectDictionaries(d3, d3);
testDictionary(d6); // OKExpected behavior:
No error
Actual behavior:
Error:
ts-braces-not-assignable.ts(13,16): error TS2345: Argument of type '{}' is not assignable to parameter of type 'Dictionary'.
Index signature is missing in type '{}'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript