Skip to content

async atomWithDefault shows Typescript error #2677

Answered by dai-shi
PhilipGrefe asked this question in Q&A
Discussion options

You must be logged in to vote

Check this out: https://tsplay.dev/WJk0gw

import { atom } from "jotai";
import { atomWithDefault } from "jotai/utils";

const descriptionBaseAtom = atomWithDefault<
  Promise<string | undefined> | string | undefined
>(async (get) => await Promise.resolve("foo" as string | undefined));

export const descriptionQueryAtom = atom(
  (get) => get(descriptionBaseAtom),
  (get, set, description: string) => {
    set(descriptionBaseAtom, description);
  },
);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PhilipGrefe
Comment options

Answer selected by PhilipGrefe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants