interface Person {
firstName: string
lastName: string
}
// 报错
let p: Person = {firstName: 'a', lastName: 'b', fullName: 'ab'}
// 正确
function sayHel(person: Person) {
return 'Hello ' + person.firstName + ' ' + person.lastName
}
const user = {
firstName: 'a',
lastName: 'b',
fullName: 'ab'
}
sayHel(user)
这两个情况不是一样的么,为什么一个报错另一个不报错?是因为函数参数逆变?