logoalt Hacker News

sally_glancetoday at 9:19 AM1 replyview on HN

I think the problem is the union argument type - intuitively we read "array of strings OR numbers", but actually it means "array of strings AND numbers". Probably generics would be more appropriate here, with the type param constrained to string or number. Then tsc would also complain about pushing a number without checking the item type before.


Replies

fainpultoday at 10:01 AM

If it's an "array of strings AND numbers", then it should not be allowed to call the function with a string[], because those are different types.

show 2 replies