nanostores / query

⚡️ Powerful data fetching library for Nano Stores. TS/JS. Framework agnostic.
MIT License
228 stars 10 forks source link

Compatibility with "module": "nodenext" in tsconfig.json #59

Open whoisYeshua opened 2 months ago

whoisYeshua commented 2 months ago

Hi. I'm using @nanostores/query in a TypeScript project with the "module": "nodenext" in tsconfig.json configuration.

However, I encountered an issue where some imports inside @nanostores/query are not working correctly with "module": "nodenext". Specifically, imports in "type files" (.d.ts) like import('./factory') are missing explicit extensions (.d.ts). This translates into the fact that all types from createFetcherStore become any.

Alternatively, if I switch to "module": "esnext" with "moduleResolution": "bundler", the imports work without needing explicit extensions, but then i lose "nodenext" mode.

Steps to Reproduce

  1. Set up a TypeScript project with the following tsconfig.json:
{
    "compilerOptions": {
        /* Language and Environment */
        "target": "ESNext",

        /* Modules */
        "module": "nodenext",
        "resolveJsonModule": true,

        /* Emit */
        "noEmit": true,

        /* Interop Constraints */
        "isolatedModules": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": false,
        "forceConsistentCasingInFileNames": true,

        /* Type Checking */
        "strict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noFallthroughCasesInSwitch": true,
        "verbatimModuleSyntax": true,

        /* Completeness */
        "skipLibCheck": true
    }
}
  1. Install nanostores & @nanostores/query and try to use it in the project.

  2. Try to create nanoquery store

or check this stackblitz example

Expected Behavior

The imports should work correctly with "module": "nodenext".

Suggested Fix

To ensure compatibility with "module": "nodenext", it would be helpful to add explicit extensions to the imports in @nanostores/query, such as:

import('./factory.d.ts');

Environment