8000 Control flow doesn't recognise undefined check · Issue #12600 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content < 6472 /span>
Control flow doesn't recognise undefined check #12600
@donaldpipowitch

Description

@donaldpipowitch

TypeScript Version: 2.1.1

Code

interface StdoutValue {
  stdout: string;
  stderr?: undefined;
}

interface StderrValue {
  stdout?: undefined;
  stderr: string;
}
type StreamValue = StdoutValue | StderrValue;

const stream: Array<StreamValue> = [
  { stdout: 'foo' },
  { stderr: 'bar' }
];

console.log(stream.map(value => value.stderr === undefined ? value.stdout.toUpperCase() : value.stderr.toUpperCase()));

Expected behavior:

No error with strict null checks.

Actual behavior:

Thinks value.stdout could be undefined on last line, but this is not possible.

Metadata

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0