You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用typescript-starter开发的TypeScript库安装后类型无法被识别的问题求助

使用typescript-starter开发的TypeScript库安装后类型无法被识别的问题求助

我用typescript-starter搭建了一个自定义TypeScript库,已经按规范组织了types文件夹结构。现在安装这个包之后,尝试调用其中的某个函数/服务时遇到了问题:

如图所示,我把requestbody模型作为参数传入,但在填写字段时,模型的属性完全没有代码提示,根本看不到可用的属性。

我已经尝试过一些方案(参考了Stack Overflow和GPT的建议):

  • 重启VS Code,怀疑是IntelliSense缓存问题,但没有解决

我的库构建输出是正常的,对应的类型文件和源码的文件夹结构一致,已经生成在build目录里了。

下面是我的项目配置信息:

package.json 相关配置

{
  "scripts": {
    "build": "run-p build:* && cpy README.md build",
    "build:main": "tsc -p tsconfig.json && cpy README.md build",
    "build:module": "tsc -p tsconfig.module.json && cpy README.md build",
    "fix": "run-s fix:*",
    "fix:prettier": "prettier \"src/**/*.ts\" --write",
    "fix:lint": "eslint src --ext .ts --fix",
    "test": "run-s build test:*",
    "test:lint": "eslint src --ext .ts",
    "test:unit": "nyc --silent ava",
    "check-cli": "run-s test diff-integration-tests check-integration-tests",
    "check-integration-tests": "run-s check-integration-test:*",
    "diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'",
    "watch:build": "tsc -p tsconfig.json -w",
    "watch:test": "nyc --silent ava --watch",
    "cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
    "cov:html": "nyc report --reporter=html",
    "cov:lcov": "nyc report --reporter=lcov",
    "cov:send": "run-s cov:lcov && codecov",
    "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
    "doc": "run-s doc:html && open-cli build/docs/index.html",
    "doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
    "doc:json": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --json build/docs/typedoc.json",
    "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
    "version": "standard-version",
    "reset-hard": "git clean -dfx && git reset --hard && npm i",
    "prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish"
  },
  "engines": {
    "node": ">=10"
  },
  "devDependencies": {
    "@ava/typescript": "^1.1.1",
    "@istanbuljs/nyc-config-typescript": "^1.0.1",
    "@typescript-eslint/eslint-plugin": "^4.0.1",
    "@typescript-eslint/parser": "^4.0.1",
    "ava": "^5.2.0",
    "codecov": "^3.5.0",
    "cpy-cli": "^5.0.0",
    "cspell": "^4.1.0",
    "cz-conventional-changelog": "^3.3.0",
    "eslint": "^7.8.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-eslint-comments": "^3.2.0",
    "eslint-plugin-functional": "^3.0.2",
    "eslint-plugin-import": "^2.22.0",
    "gh-pages": "^3.1.0",
    "npm-run-all": "^4.1.5",
    "nyc": "^15.1.0",
    "open-cli": "^7.2.0",
    "prettier": "^2.1.1",
    "standard-version": "^9.0.0",
    "ts-node": "^9.0.0",
    "typedoc": "^0.24.7",
    "typescript": "^4.0.2"
  },
  "files": [
    "build",
    "!**/*.spec.*",
    "!**/*.json",
    "CHANGELOG.md",
    "LICENSE",
    "README.md"
  ],
  "ava": {
    "failFast": true,
    "timeout": "60s",
    "typescript": {
      "rewritePaths": {
        "src/": "build/main/"
      }
    },
    "files": [
      "!build/module/**"
    ]
  },
  "config": {
    "commitizen": {
      "path": "cz-conventional-changelog"
    }
  },
  "prettier": {
    "singleQuote": true
  },
  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "exclude": [
      "**/*.spec.js"
    ]
  },
  "dependencies": {
    "axios": "^1.4.0",
    "dotenv": "^16.3.1",
    "form-data": "^4.0.0",
    "pino": "^8.14.1"
  }
}

tsconfig.json 配置

{
  "compilerOptions": {
    "incremental": true,
    "target": "es2017",
    "outDir": "build/main",
    "rootDir": "src",
    "moduleResolution": "node",
    "module": "commonjs",
    "declaration": true,
    "inlineSourceMap": true,
    "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
    "resolveJsonModule": true /* Include modules imported with .json extension. */,
    // "strict": true /* Enable all strict type-checking options. */,
    /* Strict Type-Checking Options */
    // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
    // "strictNullChecks": true /* Enable strict checking of null checks. */,
    // "strictFunctionTypes": true /* Enable strict checking of function types. */,
    // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
    // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
    // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
    /* Additional Checks */
    "noUnusedLocals": false /* Report errors on unused locals. */,
    "noUnusedParameters": false /* Report errors on unused parameters. */,
    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
    "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
    /* Debugging Options */
    "traceResolution": false /* Report module resolution log messages. */,
    "listEmittedFiles": false /* Print names of generated files part of the compilation. */,
    "listFiles": false /* Print names of files part of the compilation. */,
    "pretty": true /* Stylize errors and messages using color and context. */,
    /* Experimental Options */
    // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
    // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
    "lib": [
      "es2017",
      "dom"
    ],
    "types": [
      "node"
    ],
    "typeRoots": [
      "node_modules/@types",
      "src/types"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules/**"
  ],
  "compileOnSave": false
}

有没有大佬能帮我看看,到底哪里出问题了?怎么才能让调用方正确识别到库的类型,显示属性提示呢?

备注:内容来源于stack exchange,提问作者Nanthakumar J J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 10:59:50