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
To use isEmpty or isNotEmpty in type guards these functions should return type predicates.
In the following example there will be typescript error in the line return a + b even though we have previously checked "a" and "b" were not empty.
functionadd(a?: number,b?: number){if(isEmpty(a)||isEmpty(b)){thrownewError('a and b must be provided');}returna+b;// 'a' is possibly undefined// 'b' is possibly undefined}
I propose to alter isEmpty and isNotEmpty to return type predicates.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
To use isEmpty or isNotEmpty in type guards these functions should return type predicates.
In the following example there will be typescript error in the line
return a + b
even though we have previously checked "a" and "b" were not empty.I propose to alter isEmpty and isNotEmpty to return type predicates.
Beta Was this translation helpful? Give feedback.
All reactions