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

Fail the build if we have type errors (and fix/ignore remaining errors) #1723

Merged
merged 8 commits into from
Oct 7, 2024

Conversation

ob6160
Copy link
Member

@ob6160 ob6160 commented Sep 23, 2024

What does this change?

  • This rounds off the work I was doing a few years ago to migrate the project to Typescript
  • At the time, I got the build to a point where there were about 50+ unresolved type errors, meaning that we had to enable ignoreBuildErrors in Next to complete our migration from CRA
  • This PR ignores / refactors code where necessary in order to get our Typescript build passing, with the aim to give us a foundation to improve our types further over time

resolves #1366

Copy link

vercel bot commented Sep 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
toiletmap ✅ Ready (Inspect) Visit Preview Oct 6, 2024 7:46pm

Comment on lines -6 to -12
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

👋

Copy link

cypress bot commented Sep 24, 2024

GBPTM    Run #1338

Run Properties:  status check passed Passed #1338  •  git commit 01b970835a ℹ️: Merge 79ea338a8cf063ab5c2048ed7335563f7311da04 into 6376c1f1bac919ad083124646c3e...
Project GBPTM
Branch Review refs/pull/1723/merge
Run status status check passed Passed #1338
Run duration 01m 48s
Commit git commit 01b970835a ℹ️: Merge 79ea338a8cf063ab5c2048ed7335563f7311da04 into 6376c1f1bac919ad083124646c3e...
Committer Oliver Barnwell
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 63
View all changes introduced in this branch ↗︎

@ob6160 ob6160 force-pushed the ob/type-checking branch 3 times, most recently from 558b872 to 7c7fea8 Compare September 24, 2024 00:22
@ob6160 ob6160 added the Chromatic starts the Chromatic GitHub action workflow label Sep 24, 2024
.eslintignore Show resolved Hide resolved
src/api-client/withApollo.tsx Outdated Show resolved Hide resolved
ssr: false,
});

const LooMap = (props: LooMapProps) => {
const LooMap = (props?: Partial<LooMapProps>) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not all LooMapProps are required

Copy link
Collaborator

Choose a reason for hiding this comment

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

But are they all optional? Optional props run the risk of adding more confusion as they make things less explicit…

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case they are, they’re optional on top of the defaults that we provide

"exclude": [
"node_modules",
"src/@types/resolvers-types.ts",
"scripts/areaToDatabase/*"
Copy link
Member Author

Choose a reason for hiding this comment

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

areaToDatabase is an archive of old js code which we will eventually re-write so we have the ability to populate our areas table from scratch again

Copy link
Member Author

Choose a reason for hiding this comment

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

so we exclude it for now as it won't pass the type checker

src/api/graphql/resolvers.ts Show resolved Hide resolved
src/api-client/withApollo.tsx Show resolved Hide resolved
src/components/LooMap/ToiletMarkerIcon.tsx Outdated Show resolved Hide resolved
src/components/LooMap/ToiletMarkerIcon.tsx Outdated Show resolved Hide resolved
src/components/LooMap/useLocateMapControl.ts Outdated Show resolved Hide resolved
src/lib/openingTimes.ts Outdated Show resolved Hide resolved
src/pages/explorer/search.page.tsx Outdated Show resolved Hide resolved
@ob6160 ob6160 added Chromatic starts the Chromatic GitHub action workflow and removed Chromatic starts the Chromatic GitHub action workflow labels Oct 6, 2024
const getIconAnchor = (dimensions: number[]) => [
dimensions[0] / 2,
dimensions[1],
const ICON_DIMENSIONS: [number, number] = [22, 34] as const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is widened to the number double. For as const to work it must be paired with satisfies.

https://chrisvaillancourt.io/posts/combining-typescript-satisfies-and-const-assertion/

if (this.options[option]) {
style = style + `${property}: ${this.options[option]};`;
const value = this.options[option as keyof LocationMarkerOptions];
if (value !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if the value is numeric? Should we add a px suffix to make it a valid CSS length?


// Remove htmlElement from props
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { htmlElement, ...rest } = props;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this would make the linter happier? Underscores are understood to be unused variables…

Suggested change
const { htmlElement, ...rest } = props;
const { htmlElement: _, ...rest } = props;

@ob6160
Copy link
Member Author

ob6160 commented Oct 7, 2024

Thanks for all the detailed comments @mxdvl — I'm going to merge this as-is and open follow-up PRs over time to continue to improve types & quality of migrated files in the project. I think just having our build step fail on type errors now will be super valuable and is something we've not turned on since we started the migration from js->ts back in '21-'22

@ob6160 ob6160 merged commit ecfa28a into main Oct 7, 2024
14 checks passed
@ob6160 ob6160 deleted the ob/type-checking branch October 7, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chromatic starts the Chromatic GitHub action workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finish Typescript migration
2 participants