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
import{assert}from'@sindresorhus/is';assert.optionalString(foo);// `foo` is narrowed to `string | undefined` now
The call signature itself may be different, perhaps assert.optional.string(foo) or assert.string(foo, { optional: true }).
I've noticed that ow supports optional checks but it does not perform TypeScript type assertion yet, so I looked here but apparently is does not support this either.
What do you think?
This might be a step towards (or inspiration to) solving sindresorhus/ow#159
The text was updated successfully, but these errors were encountered:
Hi @brandon93s, thank you for the idea, I admit I didn't think of using that construction.
However, I just tried it, and after calling assert.any([is.undefined, is.string], value), TypeScript still thinks value can be anything, instead of narrowing it down to string | undefined.
So I guess my issue could now be split in two:
Request for improvement of assert.any TypeScript assertions
Request for a new optional modifier that is just "syntatic sugar" for this construct with any + is.undefined. (The value for this "syntatic sugar" is debatable, I see, and I am not even sure of my own opinion on it anymore - I see now that the first bullet above is much more important to me)
I would like to perform an assertion such as:
The call signature itself may be different, perhaps
assert.optional.string(foo)
orassert.string(foo, { optional: true })
.I've noticed that ow supports optional checks but it does not perform TypeScript type assertion yet, so I looked here but apparently
is
does not support this either.What do you think?
This might be a step towards (or inspiration to) solving sindresorhus/ow#159
The text was updated successfully, but these errors were encountered: