TypeScript vs JavaScript: API Response Example

“Can you give an example of when #TypeScript was more useful than #JavaScript in a coding task?” - was the question I was asked at an interview this morning. It’s one of those questions that sounds simple, but it made me realise that building software and explaining how you build it are two different things. A clear example is working with API responses. With JavaScript, you only discover issues when the code runs. If the response structure changes or a property is missing, the error appears at runtime. With TypeScript, you define the expected structure of the data. The compiler then warns you immediately if something doesn’t match or if you try to access a property that doesn’t exist. The logic of the program doesn’t change, but TypeScript moves many mistakes from runtime to development time, which becomes increasingly valuable as projects grow. A good reminder for #JuniorDevelopers preparing for interviews: practice building, but also practice articulating the reasoning behind your technical choices. #typescript #javascript #softwareengineering #learninginpublic #juniorsoftwaredevelopers

  • text

Victoria Lauri you're right, using a programming language that is statically typed moves a class of programming error to the compile time phase, catching this group of bugs before the application is even deployed. Plus, it seems like the rapid progress of LLM-assisted commits is also driving the use of typed languages as Cassidy Williams reports over at the GitHub blog: https://github.blog/ai-and-ml/llms/why-ai-is-pushing-developers-toward-typed-languages/ Although the cited academic report states that a ton of of compilation errors from LLM generated code were due to typing errors. That will probably fall off a cliff as developers and models give better outcome / completion criteria that would include ensuring the app builds.

Yeah, if you are using GraphQL on the backend then using Typescript on the frontend is nice, as you can codegen all your DTOs and client libraries and stuff, it's just like a calling a function, no chance of you passing anything unexpected to the API by misreading swagger docs or anything like that. I'm not a massive fan of GraphQL overall but if you are going to use it, then my advice would be definitely to pair it with a more strongly typed language like Typescript

Enum, the native JS doesn't come with those.

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories