小编sry*_*cad的帖子

“找不到模块的声明文件”,typeRoots 文件夹中的自定义声明文件被忽略

您好,我遇到了 TypeScript 问题。我有以下目录结构:

  • package.json:顶级项目
  • node_modules/:所有已安装的库
  • tsconfig.json
  • build/:生成的文件夹
    • 索引.js
    • 处理程序.js
    • ...
  • server/: a folder with a TypeScript server built on top of the build folder
    • typings/
      • handler/
        • index.d.ts
    • tsconfig.json:
    • index.ts: a TypeScript server

The file server/tsconfig.json contains the lines

    "compilerOptions": {
        "typeRoots": [
            "../node_modules/@types",
            "./typings"
        ],
    ...
    "include": [
        "./*.ts",
        "./typings/**/*.ts"
    ],
Run Code Online (Sandbox Code Playgroud)

I import an un-typed JavaScript function in TypeScript in the file server/index.ts:

import { handler } from '../build/handler.js'
... (code using handler) ...
Run Code Online (Sandbox Code Playgroud)

The file server/typings/handler/index.d.ts contains

declare module …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript tsc tsconfig

5
推荐指数
0
解决办法
508
查看次数

标签 统计

javascript ×1

node.js ×1

tsc ×1

tsconfig ×1

typescript ×1