jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.2k stars 348 forks source link

Types exports are incorrect in package.json #312

Open marcomuser opened 2 months ago

marcomuser commented 2 months ago

According to Are The Types Wrong the types for idb are not set up correctly. The main issue is that the exports property in package.json defines only one type for both the .cjs as well as the .js file:

"exports": {
    ".": {
      "types": "./build/index.d.ts",
      "module": "./build/index.js",
      "import": "./build/index.js",
      "default": "./build/index.cjs"
    },
  },

This is, however, not possible. It needs to export a separate type declaration file for each:

"exports": {
    ".": {
      "import": {
        "types": "./build/index.d.ts",
        "default": "./build/index.js",
      },
      "require": {
        "types": "./build/index.d.cts",
        "default": "./build/index.cjs"
      }
    },

Under moduleResolution "nodenext" or "node16" in a CJS project, this leads to an import which resolves to an ESM type declaration file, but a CommonJS JavaScript file.

For context, this PR fixed the same issue in the openapi-fetch package: https://github.com/drwpow/openapi-typescript/pull/1360