[英]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'}>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.