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

}

}

Reply to this note

Please Login to reply.

Discussion

You might write like

class MyClass {

constructor(readonly opts: MyClassOpts) {

}

}

and then opts will be a member

Ah, thank you, that might be what I was after

Typescript and classes :)

Just drop both both and be happy.

I do it all with functions. Classes are a liability. (and so is typescript.