镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Initializing let variables and exhaustiveness checking #22470

Description

let tagName;
switch (kind) {
  case ListKind.Ordered:
    tagName = 'ol';
    break;
  case ListKind.Unordered:
    tagName = 'ul';
    break;
  default:
    assertNever(kind);
}
  • The inferred type of tagName is string|undefined, but should be string, AFAICT.
  • Similarly: If I give tagName the type string, I get the error: “Variable 'tagName' is used before being assigned”.

Activity

  1. ajafff commented on Mar 11, 2018

    @ajafff
    Contributor

    Control flow analysis does not know that assertNever never returns. You need to return or throw assertNever(kind); to end the control flow.

  2. rauschma commented on Mar 11, 2018

    @rauschma
    Author

    That makes sense! Thanks!

  3. locked and limited conversation to collaborators on Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions