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

docs: [no-wrapper-object-types] clean up a bit of phrasing #9363

Open
wants to merge 6 commits into
base: v8
Choose a base branch
from

Conversation

kirkwaiblinger
Copy link
Member

PR Checklist

Overview

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @kirkwaiblinger!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Jun 15, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 3821222
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/667742c4100aed0009bd69b4
😎 Deploy Preview https://deploy-preview-9363--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

@@ -10,13 +10,12 @@ import TabItem from '@theme/TabItem';
> See **https://typescript-eslint.io/rules/no-wrapper-object-types** for documentation.

The JavaScript language has a set of language types, but some of them correspond to two TypeScript types, which look similar: `boolean`/`Boolean`, `number`/`Number`, `string`/`String`, `bigint`/`BigInt`, `symbol`/`Symbol`, `object`/`Object`.
The difference is that the lowercase variants are compiler intrinsics and specify the actual _runtime types_ (that is, the return value when you use the `typeof` operator), while the uppercase variants are _structural types_ defined in the library that can be satisfied by any user-defined object with the right properties, not just the real primitives.
The difference is that the lowercase variants are compiler intrinsics and specify the actual _runtime types_ (that is, the type indicated when executing `typeof x` at runtime), while the uppercase variants are _structural types_ defined in the library that can be satisfied by any user-defined object with the right properties, including but not limited to the real primitives.
Copy link
Member Author

Choose a reason for hiding this comment

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

made slight edit here to try to clarify that it's about the runtime typeof operator in TS vs the type-time typeof operator, which also exists.

Copy link

nx-cloud bot commented Jun 15, 2024

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

🙌 lovely!

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval One team member has approved this PR; a second should be enough to merge it label Jun 16, 2024
Comment on lines 17 to 18
It is widely considered a JavaScript best practice to work directly with the built-in primitives, like `0`, rather than objects that "look like" numbers, like `new Number(0)`.
Primitives are simpler to conceptualize, work with `==` and `===` equality checks -- which their object equivalents do notDeepEqual -- and have well-known behavior around truthiness/falsiness which is common to rely on.
Copy link
Member

@Josh-Cena Josh-Cena Jun 16, 2024

Choose a reason for hiding this comment

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

Suggested change
It is widely considered a JavaScript best practice to work directly with the built-in primitives, like `0`, rather than objects that "look like" numbers, like `new Number(0)`.
Primitives are simpler to conceptualize, work with `==` and `===` equality checks -- which their object equivalents do notDeepEqual -- and have well-known behavior around truthiness/falsiness which is common to rely on.
It is widely considered a JavaScript best practice to work directly with the built-in primitives, like `0`, rather than objects that "look like" numbers, like `new Number(0)`.
Primitives work with `==` and `===` equality checks and have more commonly relied-on behavior around truthiness/falsiness, while two objects that wrap the same primitive values do not compare equal, and _all_ wrapper objects are truthy regardless of the wrapped value.
Furthermore TypeScript prevents using `Number` in places that expect `number`—if a function accepts `number`, you cannot pass a value of type `Number` to it.
You also cannot do subtraction on `Number` values.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll think about this a bit. Two things I wanna pay attention to

  1. number is the specific example in this section, but it's supposed to make a point about the primitives in general, not just numbers
  2. If we give too much justification, it can seem like this is something controversial that we're just weirdly strongly opinionated about, rather than something that's not even slightly in dispute by anyone. 😆

Copy link
Member

@Josh-Cena Josh-Cena Jun 16, 2024

Choose a reason for hiding this comment

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

That's true. Well it's up to your decision. I certainly want to keep this phrasing though:

Primitives work with == and === equality checks and have more commonly relied-on behavior around truthiness/falsiness, while two objects that wrap the same primitive values do not compare equal, and all wrapper objects are truthy regardless of the wrapped value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adapted this a bit to make space for examples, each using a different primitive type. Let me know what you think!

@@ -10,13 +10,16 @@ import TabItem from '@theme/TabItem';
> See **https://typescript-eslint.io/rules/no-wrapper-object-types** for documentation.

The JavaScript language has a set of language types, but some of them correspond to two TypeScript types, which look similar: `boolean`/`Boolean`, `number`/`Number`, `string`/`String`, `bigint`/`BigInt`, `symbol`/`Symbol`, `object`/`Object`.
Copy link
Member

Choose a reason for hiding this comment

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

While we're here 😄 I'm re-reading this and finding it hard to parse... maybe:

Suggested change
The JavaScript language has a set of language types, but some of them correspond to two TypeScript types, which look similar: `boolean`/`Boolean`, `number`/`Number`, `string`/`String`, `bigint`/`BigInt`, `symbol`/`Symbol`, `object`/`Object`.
The JavaScript language has a set of built-in ("intrinsic") type pairs which look similar: `boolean`/`Boolean`, `number`/`Number`, `string`/`String`, `bigint`/`BigInt`, `symbol`/`Symbol`, and `object`/`Object`.

Copy link

codecov bot commented Jun 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.42%. Comparing base (5cd80ca) to head (3821222).
Report is 3 commits behind head on v8.

Additional details and impacted files
@@            Coverage Diff             @@
##               v8    #9363      +/-   ##
==========================================
+ Coverage   87.39%   87.42%   +0.03%     
==========================================
  Files         390      390              
  Lines       13218    13245      +27     
  Branches     3829     3833       +4     
==========================================
+ Hits        11552    11580      +28     
+ Misses       1364     1363       -1     
  Partials      302      302              
Flag Coverage Δ
unittest 87.42% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 2 files with indirect coverage changes

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 approval One team member has approved this PR; a second should be enough to merge it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants