Angular 11:为什么编译器在编译期间找不到'GeolocationPosition'?“找不到名称'GeolocationPosition'"; [英] Angular 11: Why can't the compiler find 'GeolocationPosition' during compiling? "Cannot find name 'GeolocationPosition'"
问题描述
为什么角度编译器找不到 GeolocationPosition
和 GeolocationPositionError
?VSC不会给出错误,只有在编译时才会给出错误.
Why does the angular compiler can't find GeolocationPosition
and GeolocationPositionError
? VSC doesn't give an error and only during compiling it gives me an error.
Error: src/app/modules/shared/services/position.service.ts:10:46 - error TS2304: Cannot find name 'GeolocationPosition'.
10 private positionSource = new ReplaySubject<GeolocationPosition>(1);
我通过改用 any
类型来解决此问题,但是我很好奇为什么Angular会给我错误以及如何解决此问题.
I worked around this by putting the any
type instead, but I'm just curious why Angular is giving me the error and how I can fix this.
我已经尝试了不同的编译器目标( es5
, es6
, es2018
),但是没有运气.已经安装了 @ types/core-js
,但是也没有任何运气.我可能缺少任何@types模块吗?
I've already tried different compiler targets (es5
, es6
, es2018
) but with no luck. Already installed @types/core-js
but also without any luck. Is there any @types module that I'm missing perhaps?
这是我当前的tsconfig.json
This is my current tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
推荐答案
在打字稿4.0.x中,此类型称为 Position
.在打字稿4.1.x中,它已重命名为 GeolocationPosition
.
In typescript 4.0.x this type was called Position
. In typescript 4.1.x it was renamed to GeolocationPosition
.
我想您会发现您的VS Code使用的是内置的打字稿版本,而您的项目使用的是较早版本.
I think you'll find that your VS Code is using its built in version of typescript and that your project is using an earlier version.
要解决:
npm install --save-dev typescript@4.1.2
这篇关于Angular 11:为什么编译器在编译期间找不到'GeolocationPosition'?“找不到名称'GeolocationPosition'";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!