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

[BUG] types found but incorrect when using moduleResolution: "Bundler" #58

Open
fredericrous opened this issue Mar 19, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@fredericrous
Copy link

fredericrous commented Mar 19, 2024

Describe the bug

typings for zustand-middleware-yjs cannot be imported, see the error message


⚠ Error (TS7016)  | 

Could not find a declaration file for module 
"zustand-middleware-yjs"
 . /project/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/zustand-middleware-yjs/dist/yjs.mjs implicitly has an 
any
 type.

  | There are types at /project/node_modules/zustand-middleware-yjs/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The zustand-middleware-yjs' library may need to update its package.json or typings. -- | --


To Reproduce
Steps to reproduce the behavior:

  • configure your tsconfig with compilerOptions.moduleResolution: "Bundler"
  • import zustand-middleware-yjs

Expected behavior
typings are expected to be imported correctly like when I set moduleResolution to node

Versions (please complete the following information):
yjs v1.3.1

solution seems to be to change how the exports are referenced in package.json, see microsoft/TypeScript#52363 (comment)

@fredericrous fredericrous added the bug Something isn't working label Mar 19, 2024
@0xR
Copy link

0xR commented Apr 16, 2024

running into the same issue

@0xR
Copy link

0xR commented Apr 28, 2024

@0xR
Copy link

0xR commented Apr 28, 2024

Workaround is to create "zustand-middleware-yjs.d.ts" and have it in the "include" section of you ts config.

declare module 'zustand-middleware-yjs' {
  import { StateCreator, StoreMutatorIdentifier } from 'zustand';
  import * as Y from 'yjs';

  type Yjs = <
    T extends unknown,
    Mps extends [StoreMutatorIdentifier, unknown][] = [],
    Mcs extends [StoreMutatorIdentifier, unknown][] = [],
  >(
    doc: Y.Doc,
    name: string,
    f: StateCreator<T, Mps, Mcs>,
  ) => StateCreator<T, Mps, Mcs>;

  const _default: Yjs;
  export default _default;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants