Issue
I’m trying to create a type definition for my component props:
interface ComponentProps<MappedStateProps = AppStateStateProps> extends MappedStateProps, OtherProps {
// ... some other props here too
}
MappedStateProps can either be:
- the full app state (if a
MappedStatePropstype argument is not given), or - a subset of the state (if
MappedStatePropsdefined - but it won’t always be defined, so in that case we want the full state to be assumed - a.k.aAppStateStateProps)
The error I get is: An interface can only extend an object type or intersection of object types with statically known members.
How can I solve this?
Extra info:
Example usage:
const a: ComponentProps<{ foo: string }<-- only foo in our state props
or
const b: ComponentProps <-- full state in state props
where
type AppStateStateProps = {
aStr: string;
aNum: number;
}
Solution
interface does not allow you to extends an object with statically unknown members, but type does.
Please use type instead of interface:
type ComponentProps<MappedStateProps = AppStateStateProps> = MappedStateProps & OtherProps
Answered By - captain-yossarian
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.