如何使用/声明一个外部模块,该模块不会在 Angular 11 中通过 strict 和 noImplicitReturns TypeScript 设置?

lam*_*ade 2 type-hinting typescript typescript-typings angular leaflet-geoman

我们有一个开启了严格模式的 Angular 11 应用程序。它在compilerOptions配置中有这些值tsconfig.json

"strict": true,
"noImplicitReturns": true,
Run Code Online (Sandbox Code Playgroud)

现在我们要使用外部库(传单 geoman)。库是这样导入的:

import * as L from 'leaflet';
import '@geoman-io/leaflet-geoman-free';
Run Code Online (Sandbox Code Playgroud)

不幸的是,它包括隐式any类型以及隐式any返回类型:

参数“options”隐式具有“any”类型。
缺少返回类型注释的“setLang”隐式具有“any”返回类型

如何告诉编译器在编译期间忽略模块中的这些错误,但strict在项目的其余部分保持打开模式?

Fil*_*hta 5

您可以调用编译器并使用--skipLibCheck标志来实现您想要的。

--skipLibCheckTypeScript 2.0 中添加: skiplibcheck

tsc --skipLibCheck

您可以在此线程中阅读有关为什么要使用它的更多信息:TypeScript 编译器参数“skipLibCheck”的使用