打字稿:类型'字符串'不能分配给自定义类型

问题描述 投票:1回答:1

我有这样的类型,

interface StyleProps {
  display?: 'hide' | 'active'
}

并且下面的组件正在使用该类型

<Section display={`${this.state.section !== 'chatbot' ? 'hide' : 'active'}`}>

display只能是hideactive但我仍然得到这个错误

 TS2322: Type 'string' is not assignable to type '"hide" | "active" | undefined'.

有没有办法看到display中的内容或任何我做错的事情?

reactjs typescript typescript-typings typescript2.0 styled-components
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.