ow icon indicating copy to clipboard operation
ow copied to clipboard

ow.create does not return an Assertion Functions type / `asserts` annotation is missing

Open sounisi5011 opened this issue 3 years ago • 1 comments

Currently, ow() funciton is of type Assertion Functions.

https://github.com/sindresorhus/ow/blob/f26115d48523933f061526b44eb421db322556db/source/index.ts#L31-L46

However, the ReusableValidator returned by ow.create() is not an Assertion Functions type. ReusableValidator returns a void type! In addition, the value argument does not seem to be of type unknown...

https://github.com/sindresorhus/ow/blob/f26115d48523933f061526b44eb421db322556db/source/index.ts#L53-L60

For this reason, using ow.create() in TypeScript does not provide proper type validation.

sounisi5011 avatar May 28 '21 16:05 sounisi5011

I have added something to help with this in #224. The problem why we can't simply write asserts value is T instead of void here is the same why the following exists: https://github.com/sindresorhus/ow/blob/3384c4eb1b9093a5efc0ea8ad7077e0e4a21f3b8/source/index.ts#L122-L125

cpiber avatar Sep 24 '21 11:09 cpiber