vidom icon indicating copy to clipboard operation
vidom copied to clipboard

defaultAttrs in typescript

Open LexRiver opened this issue 6 years ago • 2 comments

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

LexRiver avatar Apr 15 '19 09:04 LexRiver

Unfortunately there's no any good way to express defaultAttrs with TypeScript right now. You can use this.attrs.value! to make ts happy.

dfilatov avatar Apr 23 '19 09:04 dfilatov

ok

LexRiver avatar Apr 23 '19 12:04 LexRiver