-
I saw this error with my own code, but just to make sure, copy/pasted the example usage of
which results in the following error:
Has anyone used |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
TypeScript playground doesn't show errors: https://tsplay.dev/wQRE1N |
Beta Was this translation helpful? Give feedback.
-
The reason is |
Beta Was this translation helpful? Give feedback.
-
Greetings from Kyoto! I'm trying to set-up a provider for a few atoms in a test environment (Primitive atoms and Atoms with Storage). I'm using vitest and happy DOM. I've implemented the suggested TestProvider as suggested here https://jotai.org/docs/guides/testing#injected-values . My problem is with the typing for the type InferAtomTuples<T> = {
[K in keyof T]: T[K] extends readonly [infer A, unknown] ? A extends WritableAtom<unknown, infer Args, infer _Result> ? readonly [A, Args[0]] : T[K] : never;
}; Any idea how this reusable TestProvider from the documentation might be typed such that there is no need to typecast? Here is my attempt below: import { FunctionComponent, PropsWithChildren } from "react"
import { Provider, WritableAtom } from "jotai"
import { useHydrateAtoms } from "jotai/utils"
export type AnyWritableAtom = WritableAtom<unknown, never[], unknown>
interface InitialProps extends PropsWithChildren {
initialValues: Array<readonly [AnyWritableAtom, unknown]>
}
const HydrateAtoms: FunctionComponent<InitialProps> = ({
children,
initialValues,
}) => {
// Typecasting because i can't seem to make a generic type out of this one.
useHydrateAtoms(initialValues as Array<readonly [AnyWritableAtom, never]>)
return <>{children}</>
}
const JotaiTestProvider: FunctionComponent<InitialProps> = ({
children,
initialValues,
}) => {
return (
<Provider>
<HydrateAtoms initialValues={initialValues}>{children}</HydrateAtoms>
</Provider>
)
} Thank you for any potential response or suggestion! |
Beta Was this translation helpful? Give feedback.
One fix is to change es5 to es6.
Another fix is to add
as const