为什么下面的代码表现得像这样?它是 TypeScript 编译器中的错误还是缺少功能?
class MyType {
constructor(public readonly value1: string, public readonly value2: number) {
}
}
function myFunction(props: Partial<MyType>): void {
// Do something here
}
myFunction({ }); // Compiles
myFunction({ value1: 'string', value2: 42 }); // Compiles
myFunction({ wrongValue: true }); // Compile error!!
const myValue1 = {};
const myValue2 = { value1: 'string', value2: 42 };
const myValue3 = { wrongValue: true };
myFunction(myValue1); // Compiles
myFunction(myValue2); // Compiles
myFunction(myValue3); // Compiles, but why?!? I expected this not to compile!
我使用了 TypeScript 2.1.6 版