typescript
  • A crash guide to Typescript
  • Intro
    • What Typescript IS for?
    • What Typescript is NOT for?
    • Setting up tsconfig.json
  • Types are spooky! (How types work?)
  • Handling mutable code
  • The primitive types
  • Interfaces or Type Aliases? Oh, my!
  • The `class`, a creature which spans both realms
  • Structural typing
  • Control Flow Analysis
  • More advanced type syntaxes for another day
  • Generics
  • Modules
  • 3rd-party types
  • Epilogue
Powered by GitBook
On this page

Was this helpful?

  1. Intro

What Typescript is NOT for?

Writing OOP-styled code like C# or Java;

As TS is mostly "JS with types", you should just write TS as you would write JS, whatever code style you prefer. As classes are a JS feature, you could already write classy code in plain JS.

Making my code verbose, littered with type annotations; Force me into writing in OOP style;

Since it is made to fit already existing JS patterns, TS's type system is quite flexible. The type system does not strongly dictate what patterns you should use. This, paired with the heavy use of inference allows for the usual TS code to have a small amount of type annotations.

Due to the nature of static typing, you will eventually need to adapt some dynamic patterns or lean to more functional patterns, but those will be tiny and beneficial changes. More info on that ahead.

Providing a precise, sound type system like in a functional language

TypeScript main goal is to adjust to existing JS patterns, not to suggest new ones. As such, "soundness" is not a requirement, in favor or more flexible typing, even if less precise.

Real cons of using TypeScript

Setting up TS in modern frontend projects (webpack-based) used to be a pain. This has changed drastically since the Babel integration came, along with support on popular templates like create-react-app. Community support in this area has now raised a lot, bringing goodies like better library typings.

PreviousWhat Typescript IS for?NextSetting up tsconfig.json

Last updated 3 years ago

Was this helpful?