Let us say I have a function el, defined in typescript:
function el():string { .. }
I would like to remove the type violation (has no index signature) when later adding keys to el:
el.x = () => {...}
Is this possible to do without casting to any ?
So far the best solution I have found is to define a separate interface and casting to it while assigning:
interface ElFactory {
[index: string]: () => string
(): string
}
And then:
(el as ElFactory).x = () => {}
Is it possible to avoid the casting entirely ? As in, while defining the function associate it with the interface or specify the index signature while defining the function ?
Function
type? – smnbbrvel()
and which has function membersel.x()
. – lorefnon