问题描述
我正在努力获取对传单的导出名称空间的引用.我的TypeScript项目中的类型定义.
I am struggling to get a reference to an exported namespace for the leaflet type definitions in my TypeScript project.
使用npm install --save @types/leaflet
安装类型后,我的TS编译器(我正在使用VS Code)可以在类型定义文件中找到某些导出的类和接口,例如转换,类,但是我无法访问导出的任何名称空间.
After installing the types using npm install --save @types/leaflet
my TS compiler (I am using VS Code) is able to find some of the exported classes and interfaces in the type definition file, e.g. Transformation, Class, but I am unable to access any of the namespaces exported.
我需要能够引用L
全局变量,以便可以调用Leaflet API,但是编译器不会为我准备.
I need to be able to reference the L
global so I can make calls to the leaflet API, but the compiler is not picking this up for me.
我确实尝试过在TS文件中使用import语句,例如,尝试在其中使用传单
I did try using an import statement in my TS file I am trying to use leaflet in, e.g.
import * as L from 'leaflet'
但是同样,这次我仍然只能使用导入的别名访问类\接口,例如L.Transformation
But again, I can still only access the classes\interfaces this time on my imported alias, e.g. L.Transformation
我无法初始化新地图,例如,由于无法使用L
,因此无法使用L.map(...)
-地图是类型定义文件中的导出函数
I cannot initialise a new map, e.g by using L.map(...)
since L
is not accessible for me - map is an exported function in the type definition file
所以我不确定如何在我的项目中引用和使用L
全局传单.
So I am unsure how to reference and use the L
global for leaflet in my project.
任何人都可以帮忙吗?
谢谢
推荐答案
尝试使用旧版本的@ types/leaflet.我有同样的问题,并通过使用1.0.69版本解决了.npm install --save @ types/leaflet @ 1.0.69
Try using an older version of @types/leaflet. I have the same issue and solved it by using the 1.0.69 version.npm install --save @types/leaflet@1.0.69
使用高于(1.2+)的值似乎会导致此错误.
Using anything above that (1.2+) seems to lead to this error.
这篇关于安装@ types/leaflet后无法访问全局L名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!