uuidjs / uuid

Generate RFC-compliant UUIDs in JavaScript
MIT License
14.66k stars 903 forks source link

fix: apply stricter typing to the v* signatures #831

Closed robbtraister closed 3 weeks ago

robbtraister commented 4 weeks ago

The v4 function is guaranteed to return a string unless the buf argument is provided. By modifying the signature to denote this parameter as required for the Uint8Array case, we get the benefit of a stricter return type of string when simply calling v4().

broofa commented 3 weeks ago

@robbtraister Thanks for the update. This looks good.

FYI, I added this commit after realizing the overload types for v3 and v5 aren't really necessary. (Right? If I got that wrong, please let me know.)

robbtraister commented 3 weeks ago

@robbtraister Thanks for the update. This looks good.

FYI, I added this commit after realizing the overload types for v3 and v5 aren't really necessary. (Right? If I got that wrong, please let me know.)

Calling v3("value", "namespace") should always return string, but removing the overloads types it as string | Uint8Array.

Having said that, I only ever use v4, so 🤷

broofa commented 3 weeks ago

Calling v3("value", "namespace") should always return string, but removing the overloads types it as string | Uint8Array.

Ah, right... thanks for catching that!