Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #6906
Closed
Open
Issue created Apr 25, 2019 by Administrator@rootContributor

[typescript] Relax default-case rule

Created by: NeoLegends

react-scripts v3.0.0


Hey!

We're using the new ESLint-linting for TypeScript. Works great so far, but a TS feature makes a lint obsolete:

const fn = (input: 'foo' | 'bar'): string => {
  switch (input) {
    case 'foo':
      return 'a';
    case 'bar':
      return 'b';
    // `input` can't have any other value than `foo` or `bar`
    // (so this switch is guaranteed to be exhausive), yet ESLint
    // complains with `default-case`
  }
}

In this case the switch is safe because TS guarantees exhausiveness, yet ESLint complains about a missing default-case. However, in this case it's actually detrimental to add a default case, because you're actively using the compiler's exhaustiveness-analysis for correctness. And you won't be warned anymore when extending the range of valid parameter values and forgetting the appropriate switch case.

As far as I can see it, there are three options:

  1. Disable the lint for TS projects
  2. Hook into tsc to validate the switch's exhausiveness and conditionally apply the lint
  3. Do nothing and leave the lint as is

I consider options 1 and 2 to be valid, and I'd prefer not to go with 3, because it removes some of TS type system's power.

Assignee
Assign to
Time tracking