0
我想知道什么foo
和bar
之间的差异是在以下接口:差异函数和方法
interface Test
{
foo(value: number): string;
bar: (value: number) => string;
}
let x: Test = {
foo: (i) => "",
bar: (i) => "",
};
我的明显,第一个是方法,而第二个是一个属性,但这是否在语义上相同?
编辑:
它似乎并不完全等效。至少在构造函数方法now
只有第一个语法似乎是有效的:
class Test
{
}
interface TestConstructor
{
new(): Test;
}
const activator = function(type: TestConstructor)
{
return new type(); // fine
}
interface TestConstructor2
{
new:() => Test;
}
const activator2 = function(type: TestConstructor2)
{
return new type(); // Error: Cannot use 'new' with an expression whose type lacks a call or construct signature.
}
但你能解释的差异,当涉及到的'''new'''keyword(见编辑零件上面的问题)? –