DEV Community


Discussion on: Convince me that types are awesome

jckuhl profile image
Jonathan Kuhl
  1. Intellisense is easier and better supported with typed languages because Intellisense knows what it's looking for. I found that I have more problems with Intellisense in JavaScript than I do in Typescript

  2. Types catch bugs at the editor level, so even before compile time, with a good editor/IDE.

  3. Types allow you to create functions that know what to expect. Suppose I have the following:

async function httpConnection(httpManager:HttpManager, request:Request): Response {
  const response = await httpManager.sendRequest(request);
  return response;

In the above snippit I know, and the compiler knows, that the httpManager, which is of type HttpManager, has a sendRequest method.

But if I do the same in JavaScript:

async function httpConnection(httpManager, request) {
  const response = await httpManager.sendRequest(request);
  return response;

Then neither the programmer nor the compiler knows that the httpManager has a sendRequest object and I could pass the function an object that doesn't have that method. Program will attempt execution and crash when it calls the function. In a typed language, this doesn't happen, because you'll catch the error at the editor level.