top | item 40366317

(no title)

chromakode | 1 year ago

Alternatively for the case of id strings with known prefixes, a unique feature of TypeScript is you can use template string literal types:

https://www.kravchyk.com/adding-type-safety-to-object-ids-ty...

discuss

order

lolinder|1 year ago

Note that the prefix was never intended to be looked at as the real problem. That's not a hash function, that's an example hash function because TFA couldn't be bothered to implement a proper one. They're not actually trying to solve the prefix problem.

kaoD|1 year ago

This is why I always use `Math.random().toString(16)` for my examples :D People often get lost on the details, but they see `Math.random()` and they instantly get it's... well, just a random thing.

comagoosie|1 year ago

Isn't there a risk with this approach that you may receive input with a repeated prefix when there's a variable of type `string` and the prefix is prepended to satisfy the type checker without checking if the prefix already exists?