I had written a really long post about NestJS, types, layers and typescript, but I realized that what I wanted to express was really more simple.
Typescript is not a language, Typescript is a tool over plain JS that provides you extra functionality, basically, static type-checking. The moment you are in runtime, you’re running plain JS and you won't have that safety net.
This means that:
- Any external data coming at runtime probably won't be type-checked.
- Any modification of objects at runtime won't be type-checked (eg, middlewares) and also will mess with the written code.
- Any validations based on types won't be checked at runtime, since types disappear.
I’ll be adding samples to know when not trust typescript.