interface Person { firstName: string; lastName: string; }function greeter(person: Person) { return "Hello, " + person.firstName + " " + person.lastName; }let user = { firstName: "Jane", lastName: "User" };document.body.innerHTML = greeter(user);
这段代码ts代码编译没问题
但是TSLint却报了一个很诡异的错
类型“{ firstName: string; lastName: string; }”的参数不能赋给类型“Person”的参数。 Type '{ firstName: string; lastName: string; }' is missing the following properties from type 'Person': name, age, getName
明明接口没有定义name, age, getName为啥说我缺失?
慕标琳琳
相关分类