edit:
IMPORTANT
As @jcalz mentions, the example as is, it is wrong, since if there is any State defined on child component, than the initialization is wrong.
As a way to ignore it, it is possible to use as key as @sychd mention, but remember this example is actually an error
I'm struggling with initializing state with typescript
So I have a component that has variable state, i.e. the component has state, but the children can also define (extra) state.
This brings the problem of trying to initialise the parent state with only the part that it knows of.
This piece of code can explain the issue
interface Default {
something: boolean
}
class A<State> {
state: State & Default = {
something: false
}
}
check: Typescript Playground
So above we see that state complains about that Default type is not assignable to Default & State
Any ideas how to solve this?
stateto a validState & Default. When in the code does it get set properly?