Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#69237 [leaflet] Forward given feature prop…
Browse files Browse the repository at this point in the history
…erty type by @someonewithpc
  • Loading branch information
someonewithpc authored Apr 14, 2024
1 parent 168988c commit be8f915
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
5 changes: 5 additions & 0 deletions types/leaflet/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"@definitelytyped/no-unnecessary-generics": "off"
}
}
26 changes: 16 additions & 10 deletions types/leaflet/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2063,23 +2063,26 @@ export class Polyline<T extends geojson.GeometryObject = geojson.LineString | ge
options: PolylineOptions;
}

export function polyline(latlngs: LatLngExpression[] | LatLngExpression[][], options?: PolylineOptions): Polyline;
export function polyline<T extends geojson.GeometryObject = geojson.LineString | geojson.MultiLineString, P = any>(
latlngs: LatLngExpression[] | LatLngExpression[][],
options?: PolylineOptions,
): Polyline<T, P>;

export class Polygon<P = any> extends Polyline<geojson.Polygon | geojson.MultiPolygon, P> {
constructor(latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][], options?: PolylineOptions);
}

export function polygon(
export function polygon<P = any>(
latlngs: LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][],
options?: PolylineOptions,
): Polygon;
): Polygon<P>;

export class Rectangle<P = any> extends Polygon<P> {
constructor(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions);
setBounds(latLngBounds: LatLngBoundsExpression): this;
}

export function rectangle(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions): Rectangle;
export function rectangle<P = any>(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions): Rectangle<P>;

export interface CircleMarkerOptions extends PathOptions {
radius: number;
Expand All @@ -2098,7 +2101,7 @@ export class CircleMarker<P = any> extends Path {
feature?: geojson.Feature<geojson.Point, P> | undefined;
}

export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker;
export function circleMarker<P = any>(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker<P>;

export type CircleOptions = CircleMarkerOptions;

Expand All @@ -2112,8 +2115,11 @@ export class Circle<P = any> extends CircleMarker<P> {
setStyle(style: PathOptions): this;
}

export function circle(latlng: LatLngExpression, options: CircleMarkerOptions): Circle;
export function circle(latlng: LatLngExpression, radius: number, options: CircleMarkerOptions): Circle; // deprecated!
export function circle<P = any>(latlng: LatLngExpression, options: CircleMarkerOptions): Circle<P>;
/**
* @deprecated Passing the radius outside the options is deperecated. Use {@link circle:1} instead.
*/
export function circle<P = any>(latlng: LatLngExpression, radius: number, options?: CircleMarkerOptions): Circle<P>;

export interface RendererOptions extends LayerOptions {
padding?: number | undefined;
Expand Down Expand Up @@ -2223,7 +2229,7 @@ export class LayerGroup<P = any> extends Layer {
/**
* Create a layer group, optionally given an initial set of layers and an `options` object.
*/
export function layerGroup(layers?: Layer[], options?: LayerOptions): LayerGroup;
export function layerGroup<P = any>(layers?: Layer[], options?: LayerOptions): LayerGroup<P>;

/**
* Extended LayerGroup that also has mouse events (propagated from
Expand Down Expand Up @@ -2265,7 +2271,7 @@ export class FeatureGroup<P = any> extends LayerGroup<P> {
/**
* Create a feature group, optionally given an initial set of layers.
*/
export function featureGroup(layers?: Layer[], options?: LayerOptions): FeatureGroup;
export function featureGroup<P = any>(layers?: Layer[], options?: LayerOptions): FeatureGroup<P>;

export type StyleFunction<P = any> = (feature?: geojson.Feature<geojson.GeometryObject, P>) => PathOptions;

Expand Down Expand Up @@ -3078,7 +3084,7 @@ export class Marker<P = any> extends Layer {
protected _shadow: HTMLElement | undefined;
}

export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker;
export function marker<P = any>(latlng: LatLngExpression, options?: MarkerOptions): Marker<P>;

export namespace Browser {
// sorting according to https://leafletjs.com/reference-1.5.0.html#browser
Expand Down
10 changes: 7 additions & 3 deletions types/leaflet/leaflet-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,17 @@ interface MyProperties {
testProperty: string;
}

(L.polygon(simplePolygonLatLngs) as L.Polygon<MyProperties>).feature.properties.testProperty = "test";
// $ExpectType MyProperties
let polygonFeatureProperties = L.polygon<MyProperties>(simplePolygonLatLngs).feature.properties;
polygonFeatureProperties.testProperty = "test";

(L.marker([1, 2], {
// $ExpectType MyProperties
let markerFeatureProperties = L.marker<MyProperties>([1, 2], {
icon: L.icon({
iconUrl: "my-icon.png",
}),
}) as L.Marker<MyProperties>).feature.properties.testProperty = "test";
}).feature.properties;
markerFeatureProperties.testProperty = "test";

let lg = L.layerGroup();
lg = L.layerGroup([new L.Layer(), new L.Layer()]);
Expand Down

0 comments on commit be8f915

Please sign in to comment.