Why does the save-call with myUser variable work but the call with inline value not work? Typescript playground
interface User {
username: string;
}
function save(user: Partial<User>) {
}
const myUser = {
username: 'John',
foo: 'bar',
} as const;
// no error
this.save(myUser);
// error: Argument of type '{ username: string; foo: string; }' is not assignable to parameter of type 'Partial<User>'.
// Object literal may only specify known properties, and 'foo' does not exist in type 'Partial<User>'
this.save({
username: 'John',
foo: 'bar',
});