If you write Typescript on the backend and frontend like me, you know that sometimes your backend code can end up in the frontend bundle.
The Typescript team came with ingenious idea to address this particular issue.
This feature is only available if you are using Typescript v3.8.3, so the question is: What do you do if you are stuck on older version?
- You could upgrade, but I am sure you are stuck at an old version for a good reason
- You could also implement the feature yourself!
This trick comes in handy when you have
emitDecoratorMetadata set to true.
In example below, we want to prevent
This is how we achieve this behavior
The type keyword gives developers ability to take advantage of all typing information available to them, without worrying about exposing the actual code to the end user.
Clap if you find this insightful and share your own Typescript tricks in the comment section!