#how to add objectum params in new class?

1 messages · Page 1 of 1 (latest)

neon prawn
#

how can I pass proppers as objects to a class so that the constructor interprets them immediately?

Expamle:


export Class MyClass {
tableName: string;
rows: any;
value: any;
where: any;

  constructor(tableName: string, rows?: any, value?: any, where?: any) {
    this.tableName = tableName;
    this.rows = rows;
    this.value = value;
    this.where = where;
  }
}

new MyClass({tableName: 'example', etc...});```
sage loom
#

That'd look more like this:

type MyClassOptions = {
   tableName: string,
   // ,.. etc
}

class MyClass {
  constructor({ tableName }: MyClassOptions) {
    
  }
} 
#

If you want your constructor to take an object, then you'd define it that way.

neon prawn
#

Thanks ❤️

snow dawn
#

!resolved