Closed
Description
Returned objects of arrow functions can have more properties than the type specified in the variable declaration .
TypeScript Version: 4.1.2 / 4.2.0-dev.20201207
Search Terms:
arrow function return type covariant additional properties
Code
type MyResult = { foo: string };
const arrowProvider: () => MyResult = () => ({ foo: 'bar', bar: 'foo' });
// no error
function funcProvider(): MyResult {
return { foo: 'bar', bar: 'foo' }; // error
}
Expected behavior:
Both funcProvider
and arrowProvider
should not compile because of the superfluous property bar
in there.
Actual behavior:
Only funcProvider
triggers a compile-error
Related Issues: