Skip to content

Initializing let variables and exhaustiveness checking #22470

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
rauschma opened this issue Mar 11, 2018 · 2 comments · Fixed by #32695
Closed

Initializing let variables and exhaustiveness checking #22470

rauschma opened this issue Mar 11, 2018 · 2 comments · Fixed by #32695
Labels
Duplicate An existing issue was already created

Comments

@rauschma
Copy link

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”.
@ajafff
Copy link
Contributor

ajafff commented Mar 11, 2018

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

@rauschma
Copy link
Author

That makes sense! Thanks!

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 12, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants