-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 2.7.0-dev.20171230
Code
interface ProcessEnv {
[key: string]: string | undefined;
}
const env: ProcessEnv = { FOO: 'bar' };
const envVar: string | undefined = env.FOO;
if (typeof envVar === `string`) {
// error TS2532: Object is possibly 'undefined'.
console.log(envVar.slice(0));
}
if (typeof envVar === 'string') {
console.log(envVar.slice(0));
}Expected behavior:
Should compile fine.
Actual behavior:
error TS2532: Object is possibly 'undefined'. typeof envVar === `string` does not narrow the string | undefined union down to string.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this