Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A JSON value is best represented as a union type: boolean|string|number|array|dict.

Union types are the natural way to represent the parameters of functions that do typeof and instanceof checks, since you can easily write a list of the types that the function actually checks for.

TypeScript also has structural interface types, which are the natural way to represent the parameters of functions that don't use type guards (duck typing).



Yeah, I noticed the interface types, which seem like a much better/safer design choice. (Again, though, it's entirely possible this is just my strong-typing prejudices coming out.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: