vidom
vidom copied to clipboard
defaultAttrs in typescript
What is the proper way to use defaultAttrs with typescript?
interface Attrs{
value?:number
}
export class Test extends Component<Attrs, any, any>{
static defaultAttrs:Partial<Attrs> = {
value: 1
}
}
so when I try to use this.attrs.value I'm getting Object is possibly 'undefined'
Seems like there is the solution for react, but not works for vidom https://mattferderer.com/default-props-in-react-with-typescript
Unfortunately there's no any good way to express defaultAttrs with TypeScript right now. You can use this.attrs.value! to make ts happy.
ok