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

fix(eslint-plugin): [switch-exhaustiveness-check] better support for intersections, infinite types, non-union values#8250

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
JoshuaKGoldberg merged 6 commits intotypescript-eslint:mainfromauvred:fix/8238
Jan 30, 2024

Conversation

auvred
Copy link
Member

@auvredauvred commentedJan 14, 2024
edited
Loading

PR Checklist

Overview

I decided to fix both issues in one pr, because it was really hard to fix the first one without fixing the second.

This PR introduces better support for all combinations of unions, intersections, infinite types. It also fix suggestions more accurate.

In addition, this PR also includes several fixes for bugs that were present onmain but wasn't mentioned in issues:

1. Provide correct fixes for missingunique symbols

Before (playground):

const a = Symbol('a')const b = Symbol('b')declare const value: typeof a | typeof b  switch (value) {  case a: break;+ case unique symbol: { throw new Error('Not implemented yet: unique symbol case') }}

After:

const a = Symbol('a')const b = Symbol('b')declare const value: typeof a | typeof b  switch (value) {  case a: break;+ case b: { throw new Error('Not implemented yet: b case') }}

2. Support intersections that includes literals

Before (playground):

declareconstvalue:('aa'&{a:1})|'bb'switch(value){//      ^ Switch is not exhaustive. Cases not matched: "aa" & { a: 1; }case'aa':break;case'bb':break;}

After (no false positive):

declareconstvalue:('aa'&{a:1})|'bb'switch(value){case'aa':break;case'bb':break;}

3. Consistently add a default branch both for bare infinite types and unions of infinite types

Before (playground):

declare const value: numberswitch (value) {  case 1: break;+ default: { throw new Error('default case') }}declare const value: number | stringswitch (value) {  case 1: break;+ case string: { throw new Error('Not implemented yet: string case') }+ case number: { throw new Error('Not implemented yet: number case') }}

After:

declare const value: numberswitch (value) {  case 1: break;+ default: { throw new Error('default case') }}declare const value: number | stringswitch (value) {  case 1: break;+ default: { throw new Error('default case') }}

I've removedisUnion fromSwitchMetadata to avoid confusion: we shouldn't treat unions and non-unions differently. We should only care whether a type contains non-literal types or not

cobaltt7 reacted with hooray emoji
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@auvred!

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 commentedJan 14, 2024
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commite343dce
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/65a3d4bd5fd1b300085b2ae3
😎 Deploy Previewhttps://deploy-preview-8250--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: 98 (🟢 up 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (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.

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.

What a lovely, thoroughly tested PR! Thanks for sending this in! 👏

Comment on lines +128 to +131
for (const unionPart of tsutils.unionTypeParts(discriminantType)) {
for (const intersectionPart of tsutils.intersectionTypeParts(
unionPart,
)) {

Choose a reason for hiding this comment

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

[Non-Actionable] This feels like something we'd want a shared utility for... and, ha, I filed an issue for this back in August!#7466 (comment) ->JoshuaKGoldberg/ts-api-utils#258

Not requesting changes here. I'll go ahead and send that PR tots-api-utils and then follow up in this repo.

Choose a reason for hiding this comment

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

@JoshuaKGoldbergJoshuaKGoldberg merged commit82cb9dd intotypescript-eslint:mainJan 30, 2024
danvk pushed a commit to danvk/typescript-eslint that referenced this pull requestFeb 4, 2024
…intersections, infinite types, non-union values (typescript-eslint#8250)* feat(eslint-plugin): [switch-exhaustiveness-check] better support for intersections, infinite types, non-union values* chore: try to fix weird diff with main* refactor: no need to collect missing branches in function* fix: provide valid fixes for unique symbols* fix: valid fixes for unique symbols + few test cases for enums
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsFeb 7, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
2 participants
@auvred@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp