3 ms·
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 in
by galaxyLogic 4mo ago
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?
- dnautics 4mo agoits statically typed, but not runtime typed!
- abustamam 4mo agoI 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.
- bluepnume 4mo ago[dead]
- tancop 4mo agoits more than annotations, your code fails to compile when you get a type error at least with strict settings. if it type checks and fails at runtime that means youre missing input validation or using bad declarations for third party/legacy untyped code. or using some escape hatch like `myValue as unknown as MyType` in the wrong way.
- whstl 4mo agoLots (most?) of statically typed languages also do near zero runtime checking. They naturally use types for compilation, but the type system is trusted to forbid some invalid states. Underneath it’s all bits and bytes. Even in safe languages you need deserializers/parsers/validators. Typescript actually ends up having more checks because it runs Javascript underneath (although some might argue those barely count).