Redux 状态接口:接口只能扩展对象类型或对象类型与静态已知成员的交集

Redux state interface: An interface can only extend an object type or intersection of object types with statically known members

我正在尝试为我的组件道具创建类型定义:

interface ComponentProps<MappedStateProps = AppStateStateProps> extends MappedStateProps, OtherProps {
   // ... some other props here too
}

MappedStateProps 可以是:

我得到的错误是:An interface can only extend an object type or intersection of object types with statically known members.

我该如何解决这个问题?

额外信息:

用法示例:

const a: ComponentProps<{ foo: string }<-- only foo in our state props

const b: ComponentProps  <-- full state in state props

哪里

type AppStateStateProps = {
    aStr: string;
    aNum: number;
}

interface 不允许您扩展具有静态未知成员的对象,但 type 可以。

请使用type代替interface:

type ComponentProps<MappedStateProps = AppStateStateProps> = MappedStateProps & OtherProps