Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript 5 support #75

Open
Argeath opened this issue Sep 16, 2024 · 0 comments
Open

Typescript 5 support #75

Argeath opened this issue Sep 16, 2024 · 0 comments

Comments

@Argeath
Copy link

Argeath commented Sep 16, 2024

Hello!
I have issues with Bunshi lib when I try to bump Typescript from 4.9.5 to 5.0.4 (and every next version behaves the same).
It looks like MoleculeOrInterface<T> fails to resolve the type T for MoleculeGetter and react hooks like useMolecule etc.
type T is resolved to unknown: Argument of type Atom<string> is not assignable to parameter of type Atom<unknown> (in case of Jotai atoms). In Typescript 4.9.5 and previous it worked just fine.

Reproduction

I have modified old-typescript example for typescript 5 with following react-import-test.ts:

import { molecule, Molecule, useMolecule } from "bunshi/react";
import { atom } from "jotai/vanilla/atom";

type Atom<T> = {a: T};
const useAtom =<T>(a: Atom<T>): T => a['a'];

export const ExampleMolecule = molecule<Atom<string>>(() => {
  return {a: "I am a type test"};
});

export const DerivedMolecule = molecule((mol) => {
  const anAtom = mol(ExampleMolecule);
  return atom((get) => {
    return get(anAtom) + " and I can be derived"; // fails here: Argument of type Atom<string> is not assignable to parameter of type Atom<unknown>
  });
});

export const useMoleculeAtom = <T>(
  molecule: Molecule<T>
) => {
  return useAtom(useMolecule(molecule)); // fails here: Argument of type unknown is not assignable to parameter of type Atom<unknown>
};

export const useExample = useMoleculeAtom(DerivedMolecule);

It occurs when molecule has some generic type as type. It works for non-generics and plain data types.
But since I use Bunshi together with Jotai - it's a blocker for me :/
I couldn't find anything helpful in Typescript changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant