logoalt Hacker News

galaxyLogictoday at 1:12 AM2 repliesview on HN

As I understand it TypeScript does not enforce types at runtime. Am I correct? If so that would signify to me it is not a "typed language", like say Java for instance. Types in TypeScript are more like "annotations" for docujmenting the program. Am I correct?


Replies

abustamamtoday at 1:27 AM

I have never worked in Java. But you can certainly ship TypeScript code that does not pass typecheck and it'll run fine in the browser because the browser runs Javascript, not typescript. Obviously a decent build process will prevent code that fails typecheck from shipping, but that's not a language feature.

For runtime types I've leaned on Zod or Effect schema,which can also generate static types for you.

dnauticstoday at 1:15 AM

its statically typed, but not runtime typed!