Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Geo I] Typing functionality #5179

Merged
merged 21 commits into from
Mar 17, 2023
Merged

[Geo I] Typing functionality #5179

merged 21 commits into from
Mar 17, 2023

Conversation

madsnedergaard
Copy link
Member

@madsnedergaard madsnedergaard commented Mar 9, 2023

Description

First step in improving the geometry-related code we have: Typing it up.
I have a few more PRs coming up as I'm splitting up the work I've done :)

const output = OUT_PATH.split('/').pop();
console.info(`Generating new ${output}`);
const topo = topology({
objects: fc,
});

// We do the following to match the specific format needed for visualization
const objects: any = topo.objects.objects;
const newObjects = {};
const objects = topo.objects.objects as any;

Check warning

Code scanning / ESLint

Disallow the `any` type

Unexpected any. Specify a different type.
web/geo/types.ts Fixed Show fixed Hide fixed
web/geo/types.ts Fixed Show fixed Hide fixed
web/geo/utilities.ts Fixed Show fixed Hide fixed
web/scripts/generateZonesConfig.ts Fixed Show fixed Hide fixed
@netlify
Copy link

netlify bot commented Mar 9, 2023

Deploy Preview for phenomenal-syrniki-c5ceaa ready!

Name Link
🔨 Latest commit 80ca385
🔍 Latest deploy log https://app.netlify.com/sites/phenomenal-syrniki-c5ceaa/deploys/6414cfdf96a1e10008ad8bb5
😎 Deploy Preview https://deploy-preview-5179--phenomenal-syrniki-c5ceaa.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@madsnedergaard madsnedergaard marked this pull request as ready for review March 9, 2023 20:00
@madsnedergaard madsnedergaard changed the title [Geo] Typing functionality [Geo I] Typing functionality Mar 9, 2023
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a big one with many small changes, most of them are pretty straight forward but I do have a few questions.

web/geo/generateAggregates.ts Show resolved Hide resolved
web/geo/generateWorld.ts Show resolved Hide resolved
@@ -124,7 +125,7 @@ const mergeRatioParameters = () => {
return ratioParameters;
};

const writeJSON = (fileName: any, object: any) => {
const writeJSON = (fileName: string, object: unknown) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try and define the object type here later on but I relize it's not the simplest of types 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeeeeeeah, I started doing that, but it becomes a type of anything that can be JSON.stringify'ed, and when looking in the native NodeJS types and around on the interwebs it seems like this was most common practice. And given the actual impact of this, I did not consider it worth pursuing further - but I'm very open to changing my mind on this 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are only writing 4 kinds of JSON objects (at least right now) we could make 4 types and then a union type for this object.

These would be zone, world, exchanges and the aggregated exchanges thing.

We should already have types for the zone at least right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I started doing this, but now that I think of it I'm not sure we should limit what can be written to a JSON file - it feels counter-intuitive to be typing what output the "excluded exchanges" should be in here, when this function really shouldn't care about this 🤔 Happy to revisit this later though!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, and in any case the type errors should have been caught before we write things to json.

Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like github forgot one of my comments, weird

web/geo/generateZoneBoundingBoxes.ts Show resolved Hide resolved
@madsnedergaard
Copy link
Member Author

This was a big one with many small changes, most of them are pretty straight forward but I do have a few questions.

Thanks for reviewing - and I found it really hard with TS to split it up further, as changes to one functions types affects other places. I attempted to split it up a bit by commits though, but would love to hear your thoughts on how to make reviewing easy next time :)

Copy link
Collaborator

@tonypls tonypls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@tonypls
Copy link
Collaborator

tonypls commented Mar 10, 2023

We could make some improvements but the output is the same as it used to be and having typing will be extra nice when we want to make changes in the future!

Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approval was originally for the Geo 3 PR but the github vscode extension is behaving really weird for me lately. But there is no real changes needed here just suggestions so I'll keep it as approved.

subZoneNames?: string[];
bounding_box: number[][];
timezone: string;
[key: string]: any;

Check warning

Code scanning / ESLint

Disallow the `any` type

Unexpected any. Specify a different type.
capacity?: [number, number];
lonlat: [number, number];
rotation: number;
[key: string]: any;

Check warning

Code scanning / ESLint

Disallow the `any` type

Unexpected any. Specify a different type.
@madsnedergaard madsnedergaard enabled auto-merge (squash) March 17, 2023 20:38
@madsnedergaard madsnedergaard merged commit 5073fff into master Mar 17, 2023
@madsnedergaard madsnedergaard deleted the mn/geo/typing branch March 17, 2023 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants