Skip to content

Control flow analysis: switch (true) case #8934

Closed
@Strate

Description

@Strate

TypeScript Version:

1.9.0-dev

Code

// A self-contained demonstration of the problem follows...
interface A {}
interface B {}
interface C {}
declare function isA(arg: any): arg is A;
declare function isB(arg: any): arg is B;
declare function isC(arg: any): arg is C;

function handleAction<T>(action: T) {
  switch (true) {
    case isA(action):
    case isB(action):
      // action expected to be A|B type here
      break;
    case isC(action):
      // action expected to be C type here
      break;
    default:
      // action expected to be undefined type here
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions