Bug Report
🔎 Search Terms
type guard
🕗 Version & Regression Information
TypeScript 3.3.3+ (as per playground)
Please keep and fill in the line that best applies:
⏯ Playground Link
Playground link with error
Playground link without error but with incorrect type
💻 Code
The compiled JavaScript version works correctly, but TypeScript gives errors:
typeEmptyString=''|null|undefined;functionisEmpty(value: string|EmptyString): value is EmptyString{returnvalue===''||value===null||value===undefined;}lettest: string|null|undefined;if(isEmpty(test)){if(test===''){// Compilation error since test: null | undefined and not test: '' | null | undefinedconsole.log('Nope');}}
Also, it's weird that when I remove null from the list of types, the error disappears, but the incorrect type is still shown:
typeEmptyString=''|undefined;functionisEmpty(value: string|EmptyString): value is EmptyString{returnvalue===''||value===undefined;}lettest: string|undefined;if(isEmpty(test)){if(test===''){// No errors, but the editor displays incorrect type.console.log('Nope');}}
🙁 Actual behavior
TypeGuard ignores empty string and thinks the value can only be null or undefined.
🙂 Expected behavior
The type should include empty string. No errors expected.
Bug Report
🔎 Search Terms
type guard
🕗 Version & Regression Information
TypeScript 3.3.3+ (as per playground)
Please keep and fill in the line that best applies:
⏯ Playground Link
Playground link with error
Playground link without error but with incorrect type
💻 Code
The compiled JavaScript version works correctly, but TypeScript gives errors:
Also, it's weird that when I remove null from the list of types, the error disappears, but the incorrect type is still shown:
🙁 Actual behavior
TypeGuard ignores empty string and thinks the value can only be null or undefined.
🙂 Expected behavior
The type should include empty string. No errors expected.