実現したいこと
NextJSで扱っている、Recoilについてです。
selectorのgetやset関数の引数(newValue)にTypeScriptの型を指定したいのですが、正しい指定方法がわかりません。
以下のソースコードのように指定するとエラーとなってしまいます。
調べてもこの辺りの情報がなく、わかりませんでしたのでお聞きしたいです。
発生している問題・エラーメッセージ
No overload matches this call. Overload 2 of 2, '(options: ReadOnlySelectorOptions<void>): RecoilValueReadOnly<void>', gave the following error. Argument of type '{ key: string; get: ({ get }: { get: GetRecoilValue; getCallback: GetCallback; }) => void; set: ({ set }: { set: SetRecoilState; get: GetRecoilValue; reset: ResetRecoilState; }, newValue: string) => void; }' is not assignable to parameter of type 'ReadOnlySelectorOptions<void>'. Object literal may only specify known properties, and 'set' does not exist in type 'ReadOnlySelectorOptions<void>'.ts(2769)
該当のソースコード
js
1const testSelector = selector({2 key: 'testSelector',3 get: ({get}) => {},4 set: ({set}, newValue: string) =>5 console.log(newValue)6})7

0 コメント