-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
base: v8
Are you sure you want to change the base?
docs: [no-wrapper-object-types] clean up a bit of phrasing #9363
Conversation
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. |
✅ Deploy Preview for typescript-eslint ready!
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌 lovely!
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
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
number
is the specific example in this section, but it's supposed to make a point about the primitives in general, not just numbers- 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. 😆
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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:
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`. |
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
PR Checklist
fixes #000followup to https://github.com/typescript-eslint/typescript-eslint/pull/9102/files/f25f33396926cf0bb03eac1d02d8636987d3ec28..e078105858728c2cfe6bdf81a145feae291cb43c#r1635229512Overview