reactjs - 如何在打字稿中引用命名空间作为类型
问题描述
google-map-react
为我加载谷歌地图库。但是加载的库没有类型信息。
它只是将其返回为any
,如下所示。
function onLoadGoogleMap(): { maps: any } {
return {
maps: google.maps
}
}
所以我@types/googlemaps
自己安装了。然后我想像这样设置类型信息。但它给了我的错误Namespace 'google' has no exported member 'maps'.
function main() {
// maps is loaded as any
const { maps } = onLoadGoogleMap()
// I want type information, BUT this show me a error.
const googleMaps: {
maps: google.maps
} = {
maps: maps,
}
new googleMaps.maps.LatLng(12, 32)
}
我发现了它的@types/googlemaps
样子。这与此类似。
declare namespace google.maps {
class LatLng {
constructor(lat: number, lng: number)
}
}
如何设置命名空间的类型信息?
游乐场在这里。
感谢您的阅读。
解决方案
推荐阅读
- javascript - 如何激活隐藏输入的功能?
- python - 拖放后如何获取 PyQt5 QListView 索引以匹配模型的列表索引?
- excel - 删除 Windows Excel 中的所有空格
- vba - 访问 VBA - 使用变量名中的计数器循环
- extjs - 如何在 Ext JS 的日历组件中添加监听器?
- firebase - Firebase - Cloud Firestore(集合)
- css - 使用显示时使用 css 网格交替行颜色:行包装器的内容
- vba - 访问 vba 超链接
- flutter - 尝试在 Flutter 中创建一个新的文本文件
- c++ - C++ 向量在取消引用后没有打印正确的值?