Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
enumDATA_TYPE{First=0,Second=1,}typeGeneratedType={type:0|1;}constresponse:GeneratedType={type:1,}switch(response.type){caseDATA_TYPE.First:caseDATA_TYPE.Second:default:}
ESLint Config
module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/switch-exhaustiveness-check":[2,{"allowDefaultCaseForExhaustiveSwitch":true,"considerDefaultExhaustiveForUnions":false,"requireDefaultForNonUnion":false}]},};
tsconfig
{"compilerOptions": {"strictNullChecks":true }}Expected Result
I expect that eslint do not throw any error in switch
Actual Result
ESLint throws error in switch:
Switch is not exhaustive. Cases not matched: 0 | 1Additional Info
I useopenapi-typescript to generate response types based on swagger. It generates the following type:
typeBackendV1Components={schemas:{PublicationType:0|1;PublicationViewModel:{type:BackendV1Components["schemas"]["PublicationType"];};}}
I also have an enum that represent these values:
exportenumPUBLICATION_TYPE{Standard=0,LessonResult=1,}
But when I try to use the enum when processing the response, ESLint gives me the error described above:
constprocess=(model:BackendV1Components['schemas']['PublicationViewModel'])=>{// Switch is not exhaustive. Cases not matched: 0 | 1switch(model.type){casePUBLICATION_TYPE.Standard:casePUBLICATION_TYPE.LessonResult:default:}}
In addition, TypeScript correctly checks whether the enum member is equal to the case value. If I change theLessonResult member to2, then TypeScript will throw an error:
constprocess=(model:BackendV1Components['schemas']['PublicationViewModel'])=>{// Switch is not exhaustive. Cases not matched: 0 | 1switch(model.type){casePUBLICATION_TYPE.Standard:// Type 'PUBLICATION_TYPE.LessonResult' is not comparable to type '0 | 1'. ts(2678)casePUBLICATION_TYPE.LessonResult:default:}}