Skip to content

4.1.1-rc strange Type is not assignable to type never with yield & generators #41428

Description

@eamodio

TypeScript Version: 4.1.0-beta (4.1.1-rc too)

//cc Matt Bierner (@mjbvz)

Expected behavior:
No error on the following line

constselection=yieldstep;

As it works fine in TypeScript 4.0.5, and I'm unsure where the never is even coming from. Here is the actual source if it is interesting: https://github.com/eamodio/vscode-gitlens/blob/787bc8f3a976135d51032547e209b93267e14b2f/src%2Fcommands%2FquickCommand.steps.ts#L1794-L1814

Actual behavior:
Error on the line

Type 'QuickPickStep<QuickPickItem>' is not assignable to type 'never'.(2322)

Related Issues:

Code

exportenumDirective{Back,Cancel,LoadMore,Noop,}exportnamespaceDirective{exportfunctionis<T>(value: Directive|T): value is Directive{returntypeofvalue==='number'&&Directive[value]!=null;}}exportinterfaceQuickPickItem{label: string;description?: string;detail?: string;picked?: boolean;alwaysShow?: boolean;}exportinterfaceQuickInputStep{placeholder?: string;prompt?: string;title?: string;}exportinterfaceQuickPickStep<TextendsQuickPickItem=QuickPickItem>{placeholder?: string;title?: string;}exporttypeStepGenerator=|Generator<QuickPickStep|QuickInputStep,StepResult<void|undefined>,any|undefined>|AsyncGenerator<QuickPickStep|QuickInputStep,StepResult<void|undefined>,any|undefined>;exporttypeStepItemType<T>=TextendsQuickPickStep<infer U> ? U[] : TextendsQuickInputStep ? string : never;exportnamespaceStepResult{exportconstBreak=Symbol('BreakStep');}exporttypeStepResult<T>=typeofStepResult.Break|T;exporttypeStepResultGenerator<T>=|Generator<QuickPickStep|QuickInputStep,StepResult<T>,any|undefined>|AsyncGenerator<QuickPickStep|QuickInputStep,StepResult<T>,any|undefined>;exporttypeStepSelection<T>=TextendsQuickPickStep<infer U>
? U[]|Directive
: TextendsQuickInputStep
? string|Directive
: never;exporttypePartialStepState<T=unknown>=Partial<T>&{counter: number;confirm?: boolean;startingStep?: number};exporttypeStepState<T=Record<string,unknown>>=T&{counter: number;confirm?: boolean;startingStep?: number};exportfunctioncanPickStepContinue<TextendsQuickPickStep>(_step: T,_state: PartialStepState,_selection: StepItemType<T>|Directive,): _selection is StepItemType<T>{returnfalse;}exportfunctioncreatePickStep<TextendsQuickPickItem>(step: QuickPickStep<T>): QuickPickStep<T>{returnstep;}exportfunction*showStep<StateextendsPartialStepState&{repo: any},Contextextends{repos: any[];title: string;status: any}>(state: State,_context: Context): StepResultGenerator<QuickPickItem>{conststep: QuickPickStep<QuickPickItem>=createPickStep<QuickPickItem>({title: '',placeholder: ''});constselection: StepSelection<typeofstep>=yieldstep;returncanPickStepContinue(step,state,selection) ? selection[0] : StepResult.Break;}
Output
exportvarDirective;(function(Directive){Directive[Directive["Back"]=0]="Back";Directive[Directive["Cancel"]=1]="Cancel";Directive[Directive["LoadMore"]=2]="LoadMore";Directive[Directive["Noop"]=3]="Noop";})(Directive||(Directive={}));(function(Directive){functionis(value){returntypeofvalue==='number'&&Directive[value]!=null;}Directive.is=is;})(Directive||(Directive={}));exportvarStepResult;(function(StepResult){StepResult.Break=Symbol('BreakStep');})(StepResult||(StepResult={}));exportfunctioncanPickStepContinue(_step,_state,_selection){returnfalse;}exportfunctioncreatePickStep(step){returnstep;}exportfunction*showStep(state,_context){conststep=createPickStep({title: '',placeholder: ''});constselection=yieldstep;returncanPickStepContinue(step,state,selection) ? selection[0] : StepResult.Break;}
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2019",
"module": "ESNext"
}
}

Playground Link:Provided

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions