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

refactor: enable a few TS flags #6852

Merged
merged 6 commits into from
Mar 6, 2022
Merged

refactor: enable a few TS flags #6852

merged 6 commits into from
Mar 6, 2022

Conversation

Josh-Cena
Copy link
Collaborator

Motivation

Stricter compilation. Although 95% of them just require a !, there are actually a few potentially unsound accesses.

Have you read the Contributing Guidelines on pull requests?

Yes

@Josh-Cena Josh-Cena added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Mar 6, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 6, 2022
@netlify
Copy link

netlify bot commented Mar 6, 2022

✔️ [V2]

🔨 Explore the source changes: 9d8b184

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/62243ef98aeecf0007099ca8

😎 Browse the preview: https://deploy-preview-6852--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 48
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6852--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Mar 6, 2022

Size Change: +103 B (0%)

Total Size: 791 kB

Filename Size Change
website/build/assets/js/main.********.js 597 kB +103 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB
website/build/assets/css/styles.********.css 105 kB
website/build/index.html 38.4 kB

compressed-size-action

@Josh-Cena Josh-Cena merged commit 4db0c62 into main Mar 6, 2022
@Josh-Cena Josh-Cena deleted the jc/nouncheckedindexaccess branch March 6, 2022 05:09
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

What about using this base config?
We'll stay very strict as options get added:
https://www.npmjs.com/package/@tsconfig/strictest


Honestly not fan of noUncheckedIndexedAccess, it's not an option a lot of projects turn on and these ! everywhere only add noise

@@ -51,14 +51,13 @@ export function createExcerpt(fileString: string): string | undefined {

// Skip code block line.
if (fileLine.trim().startsWith('```')) {
const codeFence = fileLine.trim().match(/^`+/)![0]!;
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 I have no idea what is going on here and that looks like a risky change. Are tests covering this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we do have tests for this. We also have edge cases for this on our own website, so if our website builds, it's good!

@Josh-Cena
Copy link
Collaborator Author

What about using this base config?

That one has some configurations that we not necessarily agree with / are compatible with. For example, exactOptionalPropertyTypes is known for being painful for React. noPropertyAccessFromIndexSignature is IMO bad and I've also added a comment explaining why we turned it off: to be able to use process.env.NODE_ENV instead of process.env["NODE_ENV"]. (Of course you can declaration-merge and define that field explicitly, but... no)

Honestly not fan of noUncheckedIndexedAccess, it's not an option a lot of projects turn on and these ! everywhere only add noise

I think it makes sense, particularly when merging translations so we don't assume that all translation keys are present. I can't remember but maybe I fixed a bug a while ago related to this? It seems we are overall very cautious with index access in general, and remaining places just require slapping a !, which is good. A ! forces us to think about edge cases.

@slorber
Copy link
Collaborator

slorber commented Mar 9, 2022

That one has some configurations that we not necessarily agree with / are compatible with.

I agree but I'd rather disable these specific rules from a base strict config rather than enabling other rules on a less strict config => when a new strictness rule is introduced, it becomes automatically enabled so we don't forget to enable it in the future


Ok we can keep noUncheckedIndexedAccess

I find it painful in a few places like theming/CSS modules, maybe we don't want these ! to end-up in swizzled TS files too, so why not disable it in themes only for example?

@Josh-Cena
Copy link
Collaborator Author

so why not disable it in themes only for example?

Yup, that's workable. Just unsure if it reduces type-safety elsewhere... Ah, I wish TS is as configurable as a linter...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants