【问题标题】:What's the type of mapView elements like Marker and MapView, Typescript react native?Marker 和 MapView 等 mapView 元素的类型是什么,Typescript react native?
【发布时间】:2021-08-17 10:23:18
【问题描述】:

我正在使用带有 MapView 及其组件的 typescript,我需要知道要放入界面的 mapView 和标记的类型,

这是代码,

interface SelectInput {
  style?: StyleProp<ViewStyle>;
  isMapSelector?: boolean;
  isModalVisable?: boolean;

  markerLocation?: MarkerProps ; // What sould I type here
  initialRegion?: MapViewProps; // What sould I type here
  onMapViewOress?: () => object;

  onOpen: () => void;
  onClose: () => void;
}


<MapView
   initialRegion={initialRegion}   //Warining under initialRegion
   onPress={onMapViewOress}
   style={{flex: 1}}>
   <Marker coordinate={markerLocation} /> //Warining under coordinate
</MapView>

这就是我在 initialRegion 下出现的警告, “没有超载匹配这个调用。 重载 1 of 2,'(props: MapViewProps | Readonly): MapView',给出了以下错误。 输入'MapViewProps | undefined' 不可分配给类型 'Region |不明确的'。 “MapViewProps”类型缺少“Region”类型的以下属性:纬度、​​经度、纬度三角洲、经度三角洲”

这就是我在坐标下出现的警告, “没有超载匹配这个调用。 Overload 1 of 2, '(props: MarkerProps | Readonly): Marker',给出了以下错误。 输入'MarkerProps | undefined' 不可分配给类型 'LatLng |动画区域”。 类型“未定义”不可分配给类型“LatLng |动画区域'。”

【问题讨论】:

    标签: reactjs typescript react-native interface


    【解决方案1】:

    希望得到帮助:

    interface MarkerProps {
         latitude: number;
         longitude: number;
    }
    
    interface MapViewProps {
         latitude: number;
         longitude: number;
         latitudeDelta: number;
         longitudeDelta: number;
    }
    
    interface SelectInput {
      // ...
      markerLocation?: MarkerProps;
      initialRegion?: MapViewProps;
      // ...
    }
    

    【讨论】:

    • Tahnk 你,它解决了 MapViewProps 中的问题,但在坐标中显示警告,“没有重载匹配这个调用。重载 1 of 2,'(props: MarkerProps | Readonly): Marker ',给出以下错误。类型 'MarkerProps | undefined' 不可分配给类型 'LatLng | AnimatedRegion'。类型 'undefined' 不可分配给类型 'LatLng | AnimatedRegion'。"
    猜你喜欢
    • 2023-03-26
    • 2020-09-06
    • 2021-02-25
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多