Angular 8 到 9 迁移(没有 Material)index.d.ts 模块声明问题
Angular 8-to-9 migration (WITHOUT Material) index.d.ts module declaration problem
我在 index.d.ts
文件中声明了两个模块,如下所示:
declare module 'googlemaps';
declare module 'detect-resize';
这曾经工作得很好,所以我能够使用这些模块。
对于 googlemaps
我依赖于 @types/googlemaps
,但是 googlemaps
API 直到运行时才能加载,这是使用 API键。
detect-resize
只是缺少打字,因此需要 declare
。
使用 Angular 8 及更早版本,只要它们在 index.d.ts
中声明,我对这些模块没有任何问题。使用 Angular 9,这并不能解决问题,我现在无法完成构建。
我发现 Angular 9 和 index.d.ts
报告的问题,但它们都涉及 Angular Material,并通过更改所用 Material 的版本来解决问题.这显然对这里没有帮助。
有人知道这个的解决方案吗?
我不确定为什么这能解决问题,但确实如此。我的 tsconfig.app.json
文件原来是这样的:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
从 Angular 8 到 9 的自动升级修改了这个文件,如下所示:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"types": []
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
我必须像这样在 files
部分明确声明 index.d.ts
:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"types": []
},
"files": [
"main.ts",
"polyfills.ts",
"index.d.ts"
],
"include": [
"src/**/*.d.ts"
]
}
让我感到困惑的是 include
部分 (src/**/*.d.ts
) 中的 glob 应该匹配 index.d.ts
(位于 src
目录的顶部),所以为什么明确声明 index.d.ts
解决了这个问题让我有点困惑。
我在 index.d.ts
文件中声明了两个模块,如下所示:
declare module 'googlemaps';
declare module 'detect-resize';
这曾经工作得很好,所以我能够使用这些模块。
对于 googlemaps
我依赖于 @types/googlemaps
,但是 googlemaps
API 直到运行时才能加载,这是使用 API键。
detect-resize
只是缺少打字,因此需要 declare
。
使用 Angular 8 及更早版本,只要它们在 index.d.ts
中声明,我对这些模块没有任何问题。使用 Angular 9,这并不能解决问题,我现在无法完成构建。
我发现 Angular 9 和 index.d.ts
报告的问题,但它们都涉及 Angular Material,并通过更改所用 Material 的版本来解决问题.这显然对这里没有帮助。
有人知道这个的解决方案吗?
我不确定为什么这能解决问题,但确实如此。我的 tsconfig.app.json
文件原来是这样的:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
从 Angular 8 到 9 的自动升级修改了这个文件,如下所示:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"types": []
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
我必须像这样在 files
部分明确声明 index.d.ts
:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"types": []
},
"files": [
"main.ts",
"polyfills.ts",
"index.d.ts"
],
"include": [
"src/**/*.d.ts"
]
}
让我感到困惑的是 include
部分 (src/**/*.d.ts
) 中的 glob 应该匹配 index.d.ts
(位于 src
目录的顶部),所以为什么明确声明 index.d.ts
解决了这个问题让我有点困惑。