reactjs - React Typescript Storybook - 字符串文字类型
问题描述
我想String literal types
在我的组件中使用,并且我希望能够使用 Storybook 在我的故事中选择任何这些字符串。
该组件只能接收 3 种类型的字符串:LATER
| IMMEDIATELY
|FCFS
但是,我有这个错误:
Type 'string' is not assignable to type '"LATER" | "INMEDIATELY" | "FCFS"'.ts(2322) index.tsx(4, 3): The expected type comes from property 'type' which is declared here on type 'IntrinsicAttributes & LotteryCardInterface & { children?: ReactNode; }'
零件:
interface LotteryCardInterface {
type: 'LATER' | 'INMEDIATELY' | 'FCFS'
}
const LotteryCard: React.FC<LotteryCardInterface> = (props: LotteryCardInterface) =>
(<p>
{props.type}
</p>)
export default LotteryCard;
故事:
export default {
title: 'organism|LotteryCard',
component: LotteryCard,
decorators: [withKnobs]
}
const label = 'type';
const options = {
LATER: 'LATER',
INMEDIATELY: 'INMEDIATELY',
FCPS: 'FCPS',
};
const defaultValue = 'LATER';
export const Summary = () => {
const value = radios(label, options, defaultValue);
return (
<LotteryCard
type={value}
/>
)
}
知道如何解决吗?
谢谢
解决方案
推荐阅读
- html - Django/python/static files/Jinja,如何连接字符串和 jinja 表达式 INSIDE jinja 语句
- json - How to get url parameter in activated link in angular 7 and call rest api from service class
- javascript - “实时”网页与“离线”或“本地”版本的显示方式不同
- flutter - TabBarView 内容未在 setstate 上更新
- pyspark - 逐行重复值,直到找到更改
- ios - iPhone iOS 是否支持 UNIX C 语言环境?
- typescript - 无法执行 npm run env:restart
- jquery - 将文本复制到剪贴板不适用于 jQuery
- java - 在 Java8 中使用过滤器和映射提取 db 列数据
- traefik - 在 Traefik 访问日志中获取请求方案