type Foo = {
x: number;
};
function g(): Foo {
return {}; // Fails type-check
// Property 'x' is missing in type '{}' but required in type 'Foo'.
}
function f(): Foo {
return Object.create({}); // Passes!
}
function h(): Foo {
return Object.create({x: 0}); // Also passes
}
function j(): Foo {
return Object.create({x: "Hi"}); // Also passes!
}
What causes f
and j
to pass type-checking? Can TypeScript be configured so that h
passes type-checking while f
and j
fail?