为什么没有缺失错误?
interface User {
// way 1
foo(): string;
foo2(x:number): string;
// way 2
normal: () => string;
normal2: (x:number) => string;
}
let user: User = {
// way 1
foo: () => '',
foo2: () => '', // why no error since x is missing
// way 2
normal: () => '',
normal2: () => '', // why no error since x is missing
};
See this Typescript Playground
user
上调用那些函数,按预期收到了错误 - 不确定为什么在它们的定义中没有错误。 - Jack Bashford