0

I can't figure out why it works like this. While passing object directly on function call (without creating a variable) TS complains about excess properties, but while creating variable and passing this variable to function call, everything works fine. Why?

function printName(person: {first: string}): void {
    console.log(`${person.first}`);
}

printName({first: 'Mick', last: 'Big'}); //typescript gives error on 'last' property - not valid

const obj = {first: 'Jack', last: 'Jones'};
printName(obj); //valid
asdasd
  • 63
  • 1
  • 8

0 Answers0