繁体   English   中英

打字稿生成无效的三斜线指令

[英]Typescript generates invalid triple slash directive

使用 typescript 3.7.3,当我构建我的项目时,它会在我的主index.d.ts生成无效的三斜线指令。

这是我的index.d.ts

/// <reference path="types/augmentations.d.ts" />
/// <reference types="node" />
/// <reference types="fastify" />
/// <reference types="mongoose" />
/// <reference types="@keplr/backend-types/lib/mongo" />
/// <reference types="node/http" />
/// <reference types="@keplr/backend-types/lib/fastify" />
/// <reference types="fastify-cookie" />
/// <reference types="fastify-multipart" />
import * as email from './helpers/email';
import * as password from './helpers/password';
import * as token from './helpers/token';
export declare const models: {
    ...
};
export declare const plugins: {
    MainPlugin: (instance: import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse>, options: unknown, callback: (err?: import("fastify").FastifyError | undefined) => void) => void;
    RouteLessPlugin: (instance: import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse>, options: unknown, callback: (err?: import("fastify").FastifyError | undefined) => void) => void;
};

/// <reference types="node/http" />无效并产生错误。

如何防止 TS 为node/http生成三重斜线指令?

我用 TS 3.6 试过了,还是一样。

这是我的tsconfig

{
  "compilerOptions": {
    "target": "es2020",
    "lib": ["es2020", "esnext.asynciterable"],
    "module": "commonjs",
    "declaration": true,
    "outDir": "./lib",
    "rootDir": "./src",
    "strict": true,
    "incremental": true,
    "tsBuildInfoFile": "./.tsbuildinfo",
    "noUnusedLocals": true,
    "esModuleInterop": false
  },
  "include": ["./src/**/*.ts"],
  "exclude": ["**/__tests__"]
}

如果有人有同样的问题。

由于在内部库中增加了节点 http 模块,这是一个问题。

declare module 'http' { 
...
}

删除此增强解决了问题

暂无
暂无

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

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