vuex icon indicating copy to clipboard operation
vuex copied to clipboard

Fix type definitions with `moduleResolutions` `nodenext`

Open ZachHaber opened this issue 2 years ago • 3 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Typescript with nodenext resolution ignores the "typings" property completely when "exports" is specified, which causes typescript to complain that it can't find any type definitions for this package.

https://github.com/microsoft/TypeScript/issues/49160#issuecomment-1137482639

This should work fine on both v3 and v4, since both have the same issue with typescript and the exports object.

Here is the diff that solved my problem:

diff --git a/node_modules/vuex/package.json b/node_modules/vuex/package.json
index e8a851e..4cd1fce 100644
--- a/node_modules/vuex/package.json
+++ b/node_modules/vuex/package.json
@@ -7,7 +7,8 @@
     ".": {
       "module": "./dist/vuex.esm.js",
       "require": "./dist/vuex.common.js",
-      "import": "./dist/vuex.mjs"
+      "import": "./dist/vuex.mjs",
+      "types": "./types/index.d.ts"
     },
     "./": "./"
   },

This issue body was partially generated by patch-package.

ZachHaber avatar Feb 22 '23 21:02 ZachHaber

last fix commit is 2 years , I'm wondering is this package still maintained...

trim21 avatar Apr 26 '23 07:04 trim21

My workaround for the vuex type definition error:

declare module "vuex" {
  export * from "vuex/types/index.d.ts";
  export * from "vuex/types/helpers.d.ts";
  export * from "vuex/types/logger.d.ts";
  export * from "vuex/types/vue.d.ts";
}

Save the above code under an appropriate directory with a name like vuex.d.ts. This should allow TypeScript to correctly recognize the vuex module.

masaha03 avatar Jun 15 '23 02:06 masaha03

Changing the vuex package.json with :

{
  "name": "vuex",
  "version": "4.0.2",
...
  "exports": {
    ".": {
      "module": "./dist/vuex.esm-bundler.js",
      "require": "./dist/vuex.cjs.js",
      "import": {
         "default": "./dist/vuex.mjs", 
         "types": [
            "./types/index.d.ts",
            "./types/helpers.d.ts",
            "./types/logger.d.ts",
            "./types/vue.d.ts"
          ]
      }
    },
  },
...

fixes the issue

stouch avatar Dec 19 '23 12:12 stouch