You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: