Open LexRiver opened 5 years ago
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'
this.attrs.value
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.
defaultAttrs
this.attrs.value!
ok
What is the proper way to use defaultAttrs with typescript?
so when I try to use
this.attrs.value
I'm gettingObject 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