[英]string type alias is not assignable to string in Recoil with typescript
export type OrderOption =
| '-createdAt'
| 'participationFee';
export const orderState = atom<OrderOption>({
key: 'order',
default: '-createdAt',
});
interface OrderListProps {
options: { name: string; content: string }[];
recoilState: RecoilState<string>;
}
const OrderList = ({ options, recoilState }: OrderListProps) => {
return some components }
and When I try rendering当我尝试渲染时
<OrderList options={ORDER_OPTIONS} recoilState={orderState} />
It causes ts(2322) error that says RecoilState<OrderOption>
isn't assignable to RecoilState<string>
.它会导致 ts(2322) 错误说
RecoilState<OrderOption>
不能分配给RecoilState<string>
。
If vice versa I understand the error, but OrderOption
is still string overall so I don't understand why it's problematic.如果反之亦然,我理解错误,但
OrderOption
总体上仍然是字符串,所以我不明白为什么它有问题。 How can I solve this?我该如何解决这个问题?
RecoilState<'order' | '-createdAt'>
RecoilState<'order' | '-createdAt'>
is not the same as RecoilState<string>
. RecoilState<'order' | '-createdAt'>
与RecoilState<string>
。
Define recoilState
as RecoilState<'order' | '-createdAt'>
将
recoilState
定义为RecoilState<'order' | '-createdAt'>
RecoilState<'order' | '-createdAt'>
(Same as RecoilState<OrderOption>)
(与
RecoilState<OrderOption>)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.