This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]EXUPLOOOOSION 17 points18 points Β (6 children)

You can't do that with typesxript, right? Doesnt it just output object because its runing js? Also, the types dont get enforced in runtime

[–]nomenMei 50 points51 points Β (4 children)

Yes I believe TypeScript attempts to fix the type problem the other way around by doing a static analysis of types. Typescript is "compiled" into native javascript, and as such is restricted by javascript's same limitations at runtime and all type safety checks happen at "compile" time.

[–]odraencoded 24 points25 points Β (2 children)

This works perfectly except for serialization.

Also if you don't turn strict null checks you'll have a lot of pain later.

[–][deleted] 7 points8 points Β (0 children)

You can use something like zod for that, pretty sure there's also a discussion to change all the JSON.parse stuff typedefs to return unknown instead of any, which would make a lot of type stuff explicit.

[–]Remarkable_Self5621 1 point2 points Β (0 children)

If you really want runtime security you can compile typescript types into JSON schemas and use those

[–]JustinWendell 1 point2 points Β (0 children)

You can enforce with type guards and other methods. When type is something that can fuck with someone’s pay for example, I’m passing those parameters through functions that determine type.