简体   繁体   English

打字稿库 index.d.ts 未在其他打字稿应用程序中使用

[英]Typescript Library index.d.ts not used in other typescript application

Apologies in advance I'm going to attempt to explain this the best I can but please bear with me.提前道歉,我将尽力解释这一点,但请多多包涵。

I've created a library that is then installed via npm into a typescript Vue project.我创建了一个库,然后通过 npm 将其安装到 typescript Vue 项目中。 However try as I might the types (even though it comes with a index.d.ts file) are not been pulled through and I get a Module '"../../node_modules/[library name]/dist"' has no exported member [exported member] error.但是,尽我所能尝试类型(即使它带有 index.d.ts 文件)没有被拉出,我得到一个Module '"../../node_modules/[library name]/dist"' has no exported member [exported member]错误。

I'm sure I'm doing something wrong but I can't figure it out.我确定我做错了什么,但我无法弄清楚。 Any help would be greatly appreciated任何帮助将不胜感激

Here is the tsconfig.json for the library:这是该库的 tsconfig.json:

// library tsconfig.json
{
  "compilerOptions": {
    "target": "ES2018",
    "module": "esnext",
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "strictPropertyInitialization": false,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },
    "declaration": true,
    "declarationDir": "dist",
    "rootDir": "src",
    "outDir": "dist"
  },
  "include": ["src/**/*", "node_modules/@types"],
  "exclude": ["node_modules", "**/*.spec.ts"],
  "typeRoots": ["src/types/**/*", "node_modules/@types"]
}

And the package.json for the library以及库的 package.json

  "name": "LIBRARY NAME",
  "version": "1.0.0",
  "main": "dist/index.js",
  "typings": "dist/index.d.ts",
  "scripts": {
     ...
   }
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged && concurrently npm:test npm:lint"
    }
  },
  "files": [
    "dist/*"
  ],
  "engines": {
    "node": "^14.15.0",
    "npm": "^6.14.0"
  },
// deps etc etc

Seems like this was a VSCode error.似乎这是一个 VSCode 错误。 I completely closed and reopened my VSCode and it started to pickup the type declarations even when using npm link to my library.我完全关闭并重新打开了我的 VSCode,即使使用指向我的库的 npm 链接,它也开始拾取类型声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM