実現したいこと
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
ukyさんご回答の追記
インポートしてご回答いただいたコードを記述しました。
js
1import { atom, selector, DefaultValue } from 'recoil'

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/02/26 06:07 編集
2023/02/27 02:06
2023/02/27 02:16
2023/03/04 06:14