angular - Error when instantiating class: Supplied parameters do not match any signature of call target -
i have class here:
export class myclass { public name:string; public addr:string; constructor() {} }
and import here:
import { myclass } './myclass'; // , use here: class myuser { private _prop : myclass[]; constructor() { this._prop = [ new myclass({name: 'hello', addr: 'world'}) //<--- error appears ] } }
when linting error:
supplied parameters not match signature of call target
why can't instantiate class?
you haven't had mention parameter in myclass constructor. have put parameter in constructor can set value while instantiating class. move myclass
properties constructor parameter
make shortened syntax below.
export class myclass { //by having `public` on constructor shortened syntax. constructor(public name: string, public addr:string) { } } constructor() { this._prop = [ new myclass('hello', 'world') ] }
Comments
Post a Comment