【发布时间】:2022-01-24 21:32:24
【问题描述】:
为什么没有遗漏错误?
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
};
查看此打字稿Playground
【问题讨论】:
-
我尝试在
user上调用这些函数并按预期收到错误 - 不知道为什么它们的定义没有错误。 -
@AmadouBeye 不。必须有一些变量可以具有未定义的值。值不会停留在空中,而必须是变量,仅供参考。
标签: javascript typescript