这个问题同样出现在许多地方,解决方法就是简单地添加
import { } from '@types/googlemaps';
这在angular的过go 版本中起到了解决方案的作用.问题出现在我使用Angular 6时+
TS2304: Cannot find name 'google'.
TS2503: Cannot find namespace 'google'.
在我使用谷歌 map 类型的任何地方都会出现很多类似的错误.例如:
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
我可以通过在使用谷歌 map 的所有行上方插入// @ts-ignore
行来快速修复这个问题,但我对真正的修复更感兴趣.但事实上,这一点让我觉得这是一个我没有超级自信的tsconfig问题.
我可以确认googlemaps安装在node_modules/@types中,但我不确定Tconfig
ts.config
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"typeRoots": [
"node_modules/@types",
],
"lib": [
"es2017",
"dom"
]
}
}
我创建了一个Stackblitz Example,如果你查看控制台,它会抛出一个引用错误.我不知道下一步该怎么办.