sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.81k stars 107 forks source link

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

Open sounisi5011 opened 3 years ago

sounisi5011 commented 3 years ago

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.

cpiber commented 3 years ago

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