Javascript 无法使用json.map
我有要加载的Javascript 无法使用json.map,javascript,jquery,typescript,typescript-typings,Javascript,Jquery,Typescript,Typescript Typings,我有要加载的typescript代码mapbox,还有从后端加载的Json 下面是我现在如何定义变量:- const json: any = gon.hotel_info; 然后像这样使用它,在这个代码中:- data: { type: "FeatureCollection", features: json.map((item): any => { return { type: "Feature",
typescript
代码mapbox
,还有从后端加载的Json
下面是我现在如何定义变量:-
const json: any = gon.hotel_info;
然后像这样使用它,在这个代码中:-
data: {
type: "FeatureCollection",
features: json.map((item): any => {
return {
type: "Feature",
properties: {
但我不想使用任何typedef并尝试像这样使用它
const json: JSON = gon.hotel_info;
const json: Array<GeoJSONGeometry> = gon.hotel_info;
但是现在我在JSON映射中出现了一个错误
类型“JSON”上不存在属性“map”
我怎样才能解决它?我找到了问题的答案。答案是安装mapbox gl js类型并使用如下代码
const json: JSON = gon.hotel_info;
const json: Array<GeoJSONGeometry> = gon.hotel_info;
可以尝试使用
.map
方法的类型。像Array
但是泛型类型“Array”需要1个类型参数,但是哪一个呢?@chbchb55Idk,我只是猜测,我是TypeScript的noob。