Node.js tsconfig中的路径无法导入该类型

Node.js tsconfig中的路径无法导入该类型,node.js,typescript,express,tsconfig,type-declaration,Node.js,Typescript,Express,Tsconfig,Type Declaration,我正在使用TypeScript处理服务器端项目。 我在ooo.d.ts中定义了一些类型。我在tsconfig.json中设置了路径。 但是当我尝试导入我定义的类型时,它会显示错误,Module'.././@types/express custom types''没有导出的成员“CustomError”。 项目结构如下所示 ├── src │   └── routes │   └── errorHandlers.ts ├── tsconfig.json └── @types └──

我正在使用TypeScript处理服务器端项目。 我在ooo.d.ts中定义了一些类型。我在
tsconfig.json
中设置了
路径。
但是当我尝试导入我定义的类型时,它会显示错误,
Module'.././@types/express custom types''没有导出的成员“CustomError”。

项目结构如下所示

├── src
│   └── routes
│       └── errorHandlers.ts
├── tsconfig.json
└── @types
    └── express-custom-types
        └── index.d.ts

declare module "express-custom-types" {
  export type ErrorBody = { type: string; status: number; message: string };
}
我在
index.d.ts
中定义了如下类型

├── src
│   └── routes
│       └── errorHandlers.ts
├── tsconfig.json
└── @types
    └── express-custom-types
        └── index.d.ts

declare module "express-custom-types" {
  export type ErrorBody = { type: string; status: number; message: string };
}
我在tsconfig.json中定义了别名

"compilerOptions": {
    ...(omit)...

    "baseUrl": "./",
    "paths": {
      "*": ["*"],
      "@custom-types/*": ["@types/*"],
    },
然后像这样导入
errorHandlers.ts
中的类型

import { ErrorBody } from "@custom-types/express-custom-types";
但它显示错误
模块“.././@types/express custom types”没有导出的成员“ErrorBody”。


我不知道该怎么办。

您想确保您声明的模块与您尝试导入的模块具有相同的全名。这应该起作用:

声明模块“@custom-types/express-custom-types”{
导出类型ErrorBody={type:string;状态:number;消息:string};
}

声明模块…
可用于添加或增强某些外部模块的声明(通常通过
package.json安装或在“构建”过程中生成)


但这里不是这样,文件/模块是项目的一部分,您可以删除
声明模块“快速自定义类型”
包装器。

删除
声明模块“快速自定义类型”
包装器。你为什么需要它?没有这样的模块Iguess@AlekseyL. 非常感谢你。这对我有用:)那么我应该在什么时候使用
declare module
语法?顺便说一句,请写下你的评论作为回答,然后我会接受。在回答中添加了更多的信息对不起,我忘了告诉你们我的tsconfig.json设置<代码>“路径”:{“@custom types/*”:[“@types/*”],}
但是现在,关于我的问题的评论解决了这个问题。无论如何谢谢:)非常感谢!!!