Repository navigation
Leaflet circle radius should not accept undefined radius - #69221
Conversation
|
@Crakzzy Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through. This is a live comment which I will keep updated. 2 packages in this PR
Code ReviewsThis PR can be merged once it's reviewed. You can test the changes of this PR in the Playground. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 69221,
"author": "Crakzzy",
"headCommitOid": "b81b78f4d496bf8a8442eb568d6eece620d004d2",
"mergeBaseOid": "41aa59f8e323a93b98ecea69fcf67a7a0a2cfa67",
"lastPushDate": "2024-03-31T16:26:05.000Z",
"lastActivityDate": "2024-04-03T16:52:53.000Z",
"maintainerBlessed": "Waiting for Code Reviews",
"mergeOfferDate": "2024-04-03T16:38:19.000Z",
"mergeRequestDate": "2024-04-03T16:52:53.000Z",
"mergeRequestUser": "Crakzzy",
"hasMergeConflict": false,
"isFirstContribution": true,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Popular",
"pkgInfo": [
{
"name": "iitc",
"kind": "edit",
"files": [
{
"path": "types/iitc/core/iitctypes.d.ts",
"kind": "definition"
}
],
"owners": [
"McBen"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Well-liked by everyone"
},
{
"name": "leaflet",
"kind": "edit",
"files": [
{
"path": "types/leaflet/index.d.ts",
"kind": "definition"
},
{
"path": "types/leaflet/leaflet-tests.ts",
"kind": "test"
}
],
"owners": [
"alejo90",
"atd-schubert",
"mcauer",
"ronikar",
"life777",
"henrythasler",
"captain-igloo",
"someonewithpc"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Popular"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "henrythasler",
"date": "2024-04-03T16:44:46.000Z",
"isMaintainer": false
},
{
"type": "approved",
"reviewer": "someonewithpc",
"date": "2024-04-03T16:04:35.000Z",
"isMaintainer": false
}
],
"mainBotCommentID": 2028814457,
"ciResult": "pass"
} |
|
🔔 @McBen @alejo90 @atd-schubert @mcauer @ronikar @life777 @henrythasler @captain-igloo @someonewithpc — please review this PR in the next few days. Be sure to explicitly select |
henrythasler
left a comment
There was a problem hiding this comment.
According to https://leafletjs.com/reference.html#circle-option, CircleOptions.radius must always be a number.
I confirmed in the code, and you're right. @Crakzzy please add a test to prevent a possible future regression |
Okay, right on it 👍 |
|
@Crakzzy The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
|
@Crakzzy The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
|
@henrythasler Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
someonewithpc
left a comment
There was a problem hiding this comment.
The test isn't meaningful, as it asserts that 10 is a number, rather than that the options are meaningful. To this end, I made #69238, after which it will be possible to test like:
let circle = new L.Circle(latLng, 10);
circle = new L.Circle(latLng, { radius: 10 });
// @ts-expect-error
circle = new L.Circle(latLng, { radius: undefined });
// @ts-expect-error
circle = new L.Circle(latLng, { radius: null });
// @ts-expect-error
circle = new L.Circle(latLng, { radius: NaN });
// @ts-expect-error
circle = new L.Circle(latLng, { radius: '10' });
// @ts-expect-error
circle = new L.Circle(latLng, { });
// @ts-expect-error
circle = new L.Circle(latLng);
Additionally, CircleOptions should be written in terms of CircleMarkerOptions, and that should be changed to require the radius, and the factory functions should mark the options as required
For example, the following commit could replace the commits in this PR
commit eb14ccb4f403cf09570f586d8406e542cf794da5
Author: Hugo Sales
Date: Mon Apr 1 21:04:57 2024 +0000
[leaflet] Disallow `undefined` in `CircleOptions.radius`
diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts
index c8e90ef882..3b1ccaaeb0 100644
--- a/types/leaflet/index.d.ts
+++ b/types/leaflet/index.d.ts
@@ -2082,11 +2082,11 @@ export class Rectangle<P = any> extends Polygon<P> {
export function rectangle(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions): Rectangle;
export interface CircleMarkerOptions extends PathOptions {
- radius?: number | undefined;
+ radius: number;
}
export class CircleMarker<P = any> extends Path {
- constructor(latlng: LatLngExpression, options?: CircleMarkerOptions);
+ constructor(latlng: LatLngExpression, options: CircleMarkerOptions);
toGeoJSON(precision?: number | false): geojson.Feature<geojson.Point, P>;
setLatLng(latLng: LatLngExpression): this;
getLatLng(): LatLng;
@@ -2100,12 +2100,10 @@ export class CircleMarker<P = any> extends Path {
export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker;
-export interface CircleOptions extends PathOptions {
- radius: number | undefined;
-}
+export type CircleOptions = CircleMarkerOptions;
export class Circle<P = any> extends CircleMarker<P> {
- constructor(latlng: LatLngExpression, options?: CircleOptions);
+ constructor(latlng: LatLngExpression, options: CircleOptions);
constructor(latlng: LatLngExpression, radius: number, options?: CircleOptions); // deprecated!
toGeoJSON(precision?: number | false): any;
getBounds(): LatLngBounds;
@@ -2114,8 +2112,8 @@ 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(latlng: LatLngExpression, options: CircleOptions): Circle;
+export function circle(latlng: LatLngExpression, radius: number, options?: CircleOptions): Circle; // deprecated!
export interface RendererOptions extends LayerOptions {
padding?: number | undefined;
diff --git a/types/leaflet/leaflet-tests.ts b/types/leaflet/leaflet-tests.ts
index 4a7254c3a9..e27cff7a0d 100644
--- a/types/leaflet/leaflet-tests.ts
+++ b/types/leaflet/leaflet-tests.ts
@@ -990,3 +990,17 @@ L.GeoJSON.geometryToLayer(
},
},
);
+
+let circle = new L.Circle(latLng, 10);
+circle = new L.Circle(latLng, { radius: 10 });
+// @ts-expect-error
+circle = new L.Circle(latLng, { radius: undefined });
+// @ts-expect-error
+circle = new L.Circle(latLng, { radius: null });
+// @ts-expect-error
+circle = new L.Circle(latLng, { radius: '10' });
+// @ts-expect-error
+circle = new L.Circle(latLng, { });
+// @ts-expect-error
+circle = new L.Circle(latLng);
|
@Crakzzy One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you! |
|
@Crakzzy The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review. |
@someonewithpc |
I'm sorry if I came across as mean, earlier. There's no need to apologize, you didn't do anything wrong. Making mistakes is normal, and everyone has to start somewhere. I'd recommend you to run the tests locally, next time, that way no one knows if you make any mistake ;) I'd also encourage you learn
To fix that error, you can run the following command (I recommend taking the time to understand what each piece of the command does) to apply a patch to |
No, you weren't mean, don't worry. The change you provided helped to fix the error. Although that error is fixed, there are still 2 more. In the tests you provided earlier, these two still don't throw an error: And the remaining ones do. I'm not sure why only null and undefined do this. Am I missing something 😄? I know how to use the interactive rebase for squashing the commit. I will do it at the end to clean out the PR. Again, thanks for your response, and could you please let me know why is this happening? |
With the |
If you don't mind, I will do it tomorrow morning. And thanks for the explanation 👍 |
005e895 to
b81b78f
Compare
|
@someonewithpc, @henrythasler Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review? |
|
@someonewithpc |
|
@McBen This also changes |
henrythasler
left a comment
There was a problem hiding this comment.
Good job adding the tests.
Thanks, but @someonewithpc really helped me. I've never written any tests so I've learned something new 👍. |
|
Ready to merge |
|
..okay, I see it's already done. IITC uses old Leaflet v0.77. I'm not sure if old leaflet types already included the CircleMarkerOption. RN I don't have the time to move the old IITC project (no longer developed) types to the successor project IITC-CE. |
This package provides types for v0.7, though I don't know and don't want to bother checking whether that preceeded your package
It seems it didn't, which would explain why you wrote it like that |
|
@Crakzzy |
@lmachens export interface CircleMarkerStyleOptions extends PathOptions {
radius?: number | undefined;
}And then: - setStyle(options: CircleMarkerOptions): this;
+ setStyle(options: CircleMarkerStyleOptions): this;Or if you have a better idea, let me know 😃. |
When passing an undefined a NaN error is thrown. So an undefined should not be used here...
Package changed: leaflet