Closed
Description
TypeScript Version: Nightly, 3.7.5
Search Terms: excess property, computed property
Code
const a = <T>(shape: T | (() => T)): T => {
return shape instanceof Function ? shape() : shape;
}
//Case 1
a<{ x: string }>(() => ({ x: '', o: '' })); // I expect this to fail
//Case 2
a<{ x: string }>({ x: '', o: '' }); // Fails as expected
Expected behavior:
I expect Case 1
to show error similar to Case 2
because returned object contains more properties than described in generic type.
Actual behavior:
Case 1
is a valid typescript
Playground Link: Playground Link