How porting to TypeScript solved our API woes
The title is misleading because TypeScript does not implicitly do any kind of runtime type checking on data which was sent by remote clients - If the client and server both happen to be written in TypeScript by the same team, the TypeScript type system can give those developers false confidence that the API endpoints on their server enforces runtime type validation on remote user input (I&#x27;ve seen this too many times), but it does not.<p>To implement API endpoints correctly in TypeScript, you&#x27;re supposed to assume that the arguments sent by the remote client are of &#x27;unknown&#x27; type and then you need to do some explicit schema validation followed by explicit type casting. Some TypeScript libraries can make this easier but it&#x27;s misleading to say that this is a native feature of TypeScript; in fact, it is no different from doing explicit schema validation with JavaScript (there are also libraries to do this). You should always validate remote user input regardless of what programming language you use.<p>Merely getting the compile-time static type checker to shut up because the types in your client code match the types in your server code is not good enough unfortunately - In fact, it may conceal real issues by giving developers false confidence that runtime type validation is happening when in fact it is not. A hacker could write a client in a different language and intentionally send incorrect input to crash your server unless your server explicitly validates the schema.<p>The reality is that there is no guaranteed type continuity&#x2F;consistency between the client and the server. Any tool which gives the illusion that there is any kind of continuity is deceptive by design.<p>This is why I like plain JavaScript; it requires real discipline and it doesn&#x27;t give any sense of false confidence. Developers should always be on their toes. The only way to improve code quality and security is by exercising more caution, not using more tooling.<p>The benefit pointed out by the author of this article is in fact one of the few genuine gaps in TypeScript&#x27;s type safety capabilities. Praising TypeScript for this fictitious feature is only going to give developers false confidence that TS somehow takes care of input validation for them and this is going to lead them to getting hacked.