I'd like to give the static properties some initial values based on certain calculation if those properties have been decorated so I made such code:
function deco(display?: string) {
// It looks like `any` could work here instead of `T` but I don't want to use `any`
return function <T> (target: T, key: string) {
/*
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.ts(7053)
*/
if (typeof target[key] !== 'number') {
target[key] = 0
}
}
}
class A {
@deco('foo')
static foo : number
@deco('bar')
static bar : number
}
How could I make it work?