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

feat(typescript-estree): computed members discriminated unions#1349

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

Merged
bradzacher merged 7 commits intomasterfromprop-name-discriminated-unions
Dec 19, 2019

Conversation

bradzacher
Copy link
Member

@bradzacherbradzacher commentedDec 18, 2019
edited
Loading

Fixes#1345

Property names are eithercomputed: false withkey: Identifier | StringLiteral | NumberLiteral, or they arecomputed: true withkey: Expression.
the previous typings took the simple approach of just having a single type, but it made things a bit cumbersome to use.

This change creates two types for each, using thecomputed value as the key for a discriminated union.
This means that if you checknode.computed === true, then TS will narrow thekey type appropriately.

I also noticed a minor bug in theTSEnumMember handling, as the types didn't previously support the fact that it's syntactically valid to use an expression (note it's semantically invalid - TS error 1164).
It's also semantically and syntactically valid to do something likeenum Foo { ['key'] }, which really should be handled differently toenum Foo { key }, even if they mean the same thing.
So I also added acomputed prop toTSEnumMember, and gave it the same discriminated union treatment.

@bradzacherbradzacher added the enhancementNew feature or request labelDec 18, 2019
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@bradzacher!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day.

@bradzacherbradzacher changed the titlefeat: use discriminated unions for member name typesfeat(typescript-estree): use discriminated unions for member name typesDec 18, 2019
@bradzacherbradzacher changed the base branch fromminor-cleanup tomasterDecember 18, 2019 08:42
@bradzacherbradzacherforce-pushed theprop-name-discriminated-unions branch fromf8cc808 to811ad0aCompareDecember 18, 2019 08:45
property names are either `computed: false` with `key: Identifier | StringLiteral | NumberLiteral`, or they are `computed: true` with `key: Expression`.the previous typings took the simple approach of just having a single type, but it made things a bit more cumbersome.This change creates two types for each, using the `computed` value as the key for a discriminated union.This means that if you check `node.computed === true`, then TS will narrow the `key` type appropriately.I also noticed a minor bug in the `TSEnumMember` handling, as the types didn't previously support the fact that it's syntactically valid to use an expression (note it's semantically invalid - TS error 1164).It's also semantically and syntactically valid to do something like `enum Foo { ['key'] }`, which really should be handled differently to `enum Foo { key }`, even if they mean the same thing.So I also added a `computed` prop to `TSEnumMember`, and gave it the same discriminated union treatment.
@bradzacherbradzacherforce-pushed theprop-name-discriminated-unions branch fromb026aad toe91a7feCompareDecember 19, 2019 03:32
@codecov
Copy link

codecovbot commentedDec 19, 2019
edited
Loading

Codecov Report

Merging#1349 intomaster willdecrease coverage by0.01%.
The diff coverage is87.5%.

@@            Coverage Diff            @@##           master   #1349      +/-   ##=========================================- Coverage   94.01%     94%   -0.02%=========================================  Files         131     131                Lines        5867    5867                Branches     1662    1663       +1     =========================================- Hits         5516    5515       -1  Misses        186     186- Partials      165     166       +1
Impacted FilesCoverage Δ
packages/eslint-plugin/src/rules/indent.ts92.68% <ø> (ø)⬆️
packages/eslint-plugin/src/rules/prefer-for-of.ts87.32% <0%> (-1.25%)⬇️
packages/eslint-plugin/src/util/misc.ts92% <100%> (-0.86%)⬇️
packages/typescript-estree/src/convert.ts98.85% <100%> (ø)⬆️
...nt-plugin/src/rules/no-untyped-public-signature.ts100% <100%> (ø)⬆️
...escript-estree/src/semantic-or-syntactic-errors.ts87.5% <100%> (ø)⬆️

armano2
armano2 previously approved these changesDec 19, 2019
Copy link
Collaborator

@armano2armano2 left a comment
edited
Loading

Choose a reason for hiding this comment

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

besides this 2 missing test cases

LGTM 👍

armano2
armano2 previously approved these changesDec 19, 2019
@bradzacherbradzacher changed the titlefeat(typescript-estree): use discriminated unions for member name typesfeat(typescript-estree): computed members discriminated unionsDec 19, 2019
@bradzacherbradzacher merged commit013df9a intomasterDec 19, 2019
@bradzacherbradzacher deleted the prop-name-discriminated-unions branchDecember 19, 2019 05:13
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsApr 20, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@armano2armano2armano2 approved these changes

Assignees
No one assigned
Labels
enhancementNew feature or request
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Use discriminated unions to "branch" types for Property Names
2 participants
@bradzacher@armano2

[8]ページ先頭

©2009-2025 Movatter.jp