zustand-middleware-yjs icon indicating copy to clipboard operation
zustand-middleware-yjs copied to clipboard

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

Open fredericrous opened this issue 1 year ago • 3 comments

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 https://github.com/microsoft/TypeScript/issues/52363#issuecomment-1659179354

fredericrous avatar Mar 19 '24 18:03 fredericrous

running into the same issue

0xR avatar Apr 16 '24 15:04 0xR

Repro https://stackblitz.com/edit/zustand-middleware-yjs-ts?file=src%2Fmain.ts

afbeelding

0xR avatar Apr 28 '24 09:04 0xR

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;
}

0xR avatar Apr 28 '24 09:04 0xR