【发布时间】:2020-08-06 03:47:48
【问题描述】:
问题:
我正在使用没有内置类型定义的作用域包(即@ews/ntlm-client)。我在主tsconfig.json 中本地创建了自定义类型定义,然后使用了扩展tsconfig.json。但是 VSCode 抱怨扩展 tsconfig.json 找不到作用域包的定义。
我的尝试:
我创建了一个类型定义并将其放在<baseurl>\typedefs\@types\@ews\ntlm-client\index.d.ts:
declare module '@ewsjs/ntlm-client' {
function createType1Message(workstation?: string, domain?: string): string;
function decodeType2Message(wwwAuthenticate?: string | null): any;
function createType3Message(type2msg: any, username?: string, password?: string, workstation?: string, domain?: string): string;
}
我将类型定义文件夹添加到我的<baseurl>\tsconfig.json。请注意我没有运行tsc 转译器,因为我在 JS 中编码,而不是 TS:
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"lib": ["ES2019"],
"module": "CommonJS",
"target": "ES2019",
"noEmit": true,
"typeRoots": ["./node_modules/@types", "./typedefs/@types"]
}
}
然后使用<baseurl>\a\b\tsconfig.json扩展tsconfig:
{
"extends": "../../tsconfig.json"
}
但我在<baseurl>\a\b\tsconfig.json 中收到以下 Visual Studio Code 错误:
为什么会这样?我的自定义 @types 文件夹中还有其他模块的类型定义,但它们似乎不会引发相同的错误。
我还注意到我的主要<baseurl>\tsconfig.json 似乎没有这个错误。
【问题讨论】:
-
declare module 'm' {}包装器不正确。它不会做你认为它会做的事情。删除它并像从源文件中一样导出其中的声明。此外,您应该指定"moduleResolution": "Node"。您可能需要进行其他更改,但您需要按照我的建议进行操作。 -
@AluanHaddad 你能详细说明一下吗?如果我删除
declare module 'm' {},我将得到Could not find a declaration file for module 'm'用于我定义的所有类型,而不仅仅是作用域类型。moduleResolution很好,我有module: "CommonJS" -
使用 clear 模块时,无法将其解析为文件。它必须通过确切的说明符导入。
标签: typescript typescript-typings typescript-declarations