打字稿:类型 'string' 不可分配给自定义类型
Typescript: Type 'string' is not assignable to custom type
我有这样的类型,
interface StyleProps {
display?: 'hide' | 'active'
}
下面的组件正在使用该类型
<Section display={`${this.state.section !== 'chatbot' ? 'hide' : 'active'}`}>
display
只能是 hide
或 active
但我仍然收到此错误
TS2322: Type 'string' is not assignable to type '"hide" | "active" | undefined'.
有没有办法查看 display
中的内容或我做错了什么?
如果您删除模板文字并直接传入 'hide'
或 'active'
,则可以消除此错误。
<Section display={this.state.section !== 'chatbot' ? 'hide' : 'active'}>
我有这样的类型,
interface StyleProps {
display?: 'hide' | 'active'
}
下面的组件正在使用该类型
<Section display={`${this.state.section !== 'chatbot' ? 'hide' : 'active'}`}>
display
只能是 hide
或 active
但我仍然收到此错误
TS2322: Type 'string' is not assignable to type '"hide" | "active" | undefined'.
有没有办法查看 display
中的内容或我做错了什么?
如果您删除模板文字并直接传入 'hide'
或 'active'
,则可以消除此错误。
<Section display={this.state.section !== 'chatbot' ? 'hide' : 'active'}>