[英]Typescript: Type 'string' is not assignable to custom type
I have a type like this, 我有这样的类型
interface StyleProps {
display?: 'hide' | 'active'
}
and the type is being used by component below 并且该类型正在由下面的组件使用
<Section display={`${this.state.section !== 'chatbot' ? 'hide' : 'active'}`}>
display
can only be hide
or active
but I'm still getting this error display
只能是hide
或active
但我仍然收到此错误
TS2322: Type 'string' is not assignable to type '"hide" | "active" | undefined'.
Is there any way to see what's in display
or anything im doing it wrong? 有什么办法可以查看display
或我做错了什么吗?
如果删除模板文字并直接传递'hide'
或'active'
则可以消除此错误。
<Section display={this.state.section !== 'chatbot' ? 'hide' : 'active'}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.