Global Feed Post Login
Replying to Avatar hodlbod

Does anyone else get tired of how typescript makes you annotate class members multiple times? Or am I just holding it wrong? It seems like you should only need either the class member annotations, or the constructor annotations, not both.

export type MyClassOpts = {

a: string

b: string

c: string

}

class MyClass {

a: MyClassOpts['a']

b: MyClassOpts['b']

c: MyClassOpts['c']

constructor({a, b, c}: MyClassOpts) {

this.a = a

this.b = b

this.c = c

}

}

5f
Joey 2y ago

TypeScript has this shortcut: https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties

Reply to this note

Please Login to reply.

Discussion

No replies yet.