我這裏有一類:錯誤實例化時類:提供的參數不匹配通話對象的任何簽名
export class MyClass {
public name:string;
public addr:string;
constructor() {}
}
而且我在這裏導入它:
import { MyClass } from './MyClass';
// and use it here:
class MyUser {
private _prop : MyClass[];
constructor() {
this._prop = [
new MyClass({name: 'Hello', addr: 'World'}) //<--- this is where the error appears
]
}
}
當我這樣做,我得到一個短毛線的錯誤:
Supplied parameters do not match any signature of call target
爲什麼我不能實例化我的類?
看起來像是期待Typescript具有像C#那樣的對象初始化能力。但Typescript沒有:( – Vaccano