Skip to content

Typing bug: Pick is not setting props as optional #52

@SalahAdDin

Description

@SalahAdDin

Hello, thank you for providing us with this good library.

Right now we have the following problem:

Type '{ children: (info: SearchInfo) => Element; position: string; provider: string; showMarker: boolean; showPopup: boolean; zoom: number; closeResultsOnClick: true; openSearchOnLoad: boolean; onChange: (info: SearchInfo) => void; }' is missing the following properties from type 'Pick<any, "onChange" | "search" | "map" | "children" | "zoom" | "className" | "tabIndex" | "handler" | "provider" | "customProvider" | "providerOptions" | "openSearchOnLoad" | ... 8 more ... | "popUp">': search, map, className, tabIndex, and 8 more.

The solution that linter gives is to put all missing attributes as undefined:

      <Search
        position="topleft"
        provider="OpenStreetMap"
        showMarker={false}
        showPopup={false}
        zoom={7}
        closeResultsOnClick
        openSearchOnLoad={false}
        onChange={(info: SearchInfo) => {
          onChange(info.latLng);
        }}
        search={undefined}
        map={undefined}
        className={undefined}
        tabIndex={undefined}
        handler={undefined}
        customProvider={undefined}
        providerOptions={undefined}
        inputPlaceholder={undefined}
        mapStateModifier={undefined}
        zoomPanOptions={undefined}
        markerIcon={undefined}
        popUp={undefined}
      >
        {(info: SearchInfo) => <Marker position={info?.latLng} />}
      </Search>

But this is not the best way to solve it. It is not normal since you are importing all props with Pick, so it should get all of them as optional:

/// <reference types="react" />
declare const _default: import("react").ComponentType<Pick<import("./ReactLeafletSearch").ReactLeafletSearchProps, "search" | "map" | "zoom" | "children" | "className" | "onChange" | "tabIndex" | "handler" | "provider" | "customProvider" | "providerOptions" | "openSearchOnLoad" | "closeResultsOnClick" | "inputPlaceholder" | "position" | "showMarker" | "showPopup" | "mapStateModifier" | "zoomPanOptions" | "markerIcon" | "popUp">>;
export default _default;

What's happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions