TypeScript Frameworks in 2020

Spencer
Spencer
TypeScript Frameworks in 2020

TypeScript blue and mark.

TypeScript has been steadily gaining adoption, and is in the top 3 most loved languages according to StackOverflow's 2019 Developer Survery.

Despite the growing popularity, there are fewer mature framework choices than pure Node (see my tour of Node.js frameworks).

A few major frameworks like Loopback@4, Feathers, and Adonis are all doing major rewrites from Node to TypeScript. These frameworks intend to interoperate with Node.js so users of the frameworks do not have to use TypeScript if they prefer Node.

Nest.js

Nest logo

website | github | 2021? 👍

Inspired by Angular's module system, Nest is by far the most popular TypeScript framework in 2020.

It has been growing steadily since being introduced in 2018, matching Koa's trajectory of adoption in the Node world:

Nest v Koa downloads Source

Nest has actually outpaced most Node frameworks besides Koa and Express at this point in terms of downloads per week (to be fair, it was introduced multiple years later as well).

The central features of Nest are it's dependency injection mechanism, module system, and extensive use of decorators. In fact, decorators are used to declare modules and dependencies.

Here's a standard module declaration:

import { Module } from '@nestjs/common';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';

@Module({
  controllers: [CatsController],
  providers: [CatsService],
})
export class CatsModule {}

A controller makes similar use of decorators:

import { Controller, Get, Req } from '@nestjs/common';
import { Request } from 'express';

@Controller('cats')
export class CatsController {
  @Get()
  findAll(@Req() request: Request): string {
    return 'This action returns all cats';
  }
}

I find the ability to use decorators to change parameters in controller methods both powerful and elegant. It's more expressive, declarative, and flexible than a context object that holds every possible reference for the request/response.

Modules provide a level of isolation for dependency resolution, and a module can choose which services can be exported or imported into the module.

Nest provides a number of sharp tools, but does not provide a lot of opinions what you do with them - so it supports all sorts of configurations from monolithic MVC applications to event-based microservices:

  • middleware
  • pipes for validation, among other things
  • guards for access control
  • exception filters for easily handling runtime exceptions
  • interceptors
  • testing harness

It has official packages to integrate populate ORMs like TypeORM, queuing, logging, and others.

Foal

website | github

TBD.

TS.ed

website | github

TBD.

Honorable Mentions

Here are few frameworks that aren't production ready yet but deserve a place on this list.