Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

kirkwaiblinger
Copy link
Member

@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 onhttps://opencollective.com/typescript-eslint.

@netlifyNetlify
Copy link

netlifybot commentedJun 15, 2024
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commitf7d7253
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/668b83dd41b8080008afb753
😎 Deploy Previewhttps://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 5 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 yourNetlify 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, thereturn value whenyou 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, notjust the real primitives.
The difference is that the lowercase variants are compiler intrinsics and specify the actual _runtime types_ (that is, thetype indicated whenexecuting`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 butnotlimited to the real primitives.
Copy link
MemberAuthor

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 theruntimetypeof operator in TS vs the type-timetypeof operator, which also exists.

JoshuaKGoldberg reacted with thumbs up emoji
@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedJun 15, 2024
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commitf7d7253. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 fromNxCloud.

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

🙌 lovely!

@JoshuaKGoldbergJoshuaKGoldberg added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelJun 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-CenaJosh-CenaJun 16, 2024
edited
Loading

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.

kirkwaiblinger reacted with thumbs up emoji
Copy link
MemberAuthor

@kirkwaiblingerkirkwaiblingerJun 16, 2024
edited
Loading

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, notjust numbers
  2. If we givetoo 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-CenaJosh-CenaJun 16, 2024
edited
Loading

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, andall wrapper objects are truthy regardless of the wrapped value.

kirkwaiblinger reacted with thumbs up emoji
Copy link
MemberAuthor

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`.

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 oflanguage 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 ofbuilt-in ("intrinsic") type pairswhich look similar:`boolean`/`Boolean`,`number`/`Number`,`string`/`String`,`bigint`/`BigInt`,`symbol`/`Symbol`, and`object`/`Object`.

@codecovCodecov
Copy link

codecovbot commentedJun 22, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.42%. Comparing base(d685948) to head(3821222).
Report is 94 commits behind head on v8.

Current head3821222 differs from pull request most recent headf7d7253

Pleaseupload reports for the commitf7d7253 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@##               v8    #9363      +/-   ##==========================================- Coverage   88.37%   87.42%   -0.95%==========================================  Files         419      390      -29       Lines       14610    13245    -1365       Branches     4274     3833     -441     ==========================================- Hits        12911    11580    -1331+ Misses       1375     1363      -12+ Partials      324      302      -22
FlagCoverage Δ
unittest87.42% <ø> (-0.95%)⬇️

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

see 52 files with indirect coverage changes

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Yay!

Josh-Cena
Josh-Cena previously approved these changesJun 27, 2024
Copy link
Member

@Josh-CenaJosh-Cena left a comment

Choose a reason for hiding this comment

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

I havesome reservations but I think this generally looks great

JavaScript programs typically work with the real number primitives, rather than objects that "look like" numbers.
Primitives are simpler to conceptualize and work with `==` and `===` equality checks -- which their object equivalents do notDeepEqual.
As a result, using the lowercase type names like `number` instead of the uppercase names like `Number` helps make your code behave more reliably.
The JavaScript language has a set of built-in ("intrinsic") types which look similar: `boolean`/`Boolean`, `number`/`Number`, `string`/`String`, `bigint`/`BigInt`, `symbol`/`Symbol`, and `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.

I think this loses the nuance that we tried hard to keep in the original docs. JavaScript only has eight types:number,object,string,symbol,boolean,bigint,undefined,null.Boolean,Number, etc. are subtypes ofobject. It's only in TypeScript-land where they are sort of parallel and can be compared to each other.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I actually agree. I would like to go with something more similar to the original wording as well.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Neither here nor there, but

Boolean,Number, etc. are subtypes ofobject.

TIL that

leto:object=false;// <-- TS error// BUTletb:Boolean=false;o=b;// no error lol

The wrapper types are so bad lol

Copy link
Member

@Josh-CenaJosh-CenaJul 4, 2024
edited
Loading

Choose a reason for hiding this comment

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

Yep—everything that doesn't claim to be a primitive is implicitlyobject, including{}.object does not actually mean "non-primitive"; it just means "is not definitely primitive".

kirkwaiblinger reacted with laugh emoji
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Looks great to me! Just the one nit, not a blocker if you disagree. Thanks! 🎉

Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Copy link
Member

@Josh-CenaJosh-Cena left a comment

Choose a reason for hiding this comment

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

Love this!

kirkwaiblinger reacted with heart emoji
@kirkwaiblingerkirkwaiblinger merged commit46dd42f intotypescript-eslint:v8Jul 12, 2024
32 of 61 checks passed
@kirkwaiblingerkirkwaiblinger deleted the kirk-no-wrapper-object-types-docs branchJuly 12, 2024 06:12
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJul 20, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

@Josh-CenaJosh-CenaJosh-Cena approved these changes

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@kirkwaiblinger@JoshuaKGoldberg@Josh-Cena

[8]ページ先頭

©2009-2025 Movatter.jp