【发布时间】:2022-12-22 07:58:52
【问题描述】:
我开始使用反冲和打字稿。
此时,我使用默认属性来定义我的原子的每个属性类型:
const WipStateAtom = atom({
key: 'wipAtom',
default: {
data: null as IData | null,
ex: null as IEx | null,
}
});
但是是否可以使用接口/或类型来定义原子内容,例如:
export interface IWipAtom {
data: IGameData | null,
ex: IEx | null,
}
我想在函数中传递一个原子,但我不想将其键入 ANY :
const [wip, setWip] = useRecoilState(WipStateAtom);
const myFunction = (thewip: any) => { ... }
我更喜欢严格定义它的类型:
const myFunction = (thewip: IWipAtom) => { ... }
有什么方法可以输入原子吗?
【问题讨论】:
标签: reactjs typescript recoiljs