简体   繁体   中英

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> .

If vice versa I understand the error, but OrderOption is still string overall so I don't understand why it's problematic. How can I solve this?

RecoilState<'order' | '-createdAt'> RecoilState<'order' | '-createdAt'> is not the same as RecoilState<string> .


Define recoilState as RecoilState<'order' | '-createdAt'> RecoilState<'order' | '-createdAt'>

(Same as RecoilState<OrderOption>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM