/poc-typescript

Playground for learning about TypeScript

MIT LicenseMIT

PoC Typescript

Playground for learning about TypeScript

Table of Contents

General

TS from scratch

  • https://www.typescriptlang.org/docs/handbook/typescript-from-scratch.html
  • TypeScript is a language that is a superset of JavaScript: JS syntax is therefore legal TS. Syntax refers to the way we write text to form a program.
  • TypeScript is also a programming language that preserves the runtime behavior of JavaScript.
    • This means that if you move code from JavaScript to TypeScript, it is guaranteed to run the same way.
  • Roughly speaking, once TypeScript’s compiler is done with checking your code, it erases the types to produce the resulting "compiled" code. This means that once your code is compiled, the resulting plain JS code has no type information.
    • This also means that TypeScript never changes the behavior of your program based on the types it inferred
  • TypeScript doesn’t provide any additional runtime libraries.

Codely course: from JS to TS (2021)

TypeScript for JS programmers

  • https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html
  • Visual Studio Code uses TypeScript under the hood to make it easier to work with JavaScript.
  • You’ll see that there are two syntaxes for building types: Interfaces and Types. You should prefer interface. Use type when you need specific features.
  • There is already a small set of primitive types available in JavaScript: boolean, bigint, null, number, string, symbol, and undefined, which you can use in an interface.
  • One of TypeScript’s core principles is that type checking focuses on the shape that values have. This is sometimes called “duck typing” or “structural typing”.

Pending readings

Currently reading

How to migrate a project from JS to TS

Interesting links

  • TSyringe: dependency injection
  • InversifyJS: A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
    • It uses constants to "hack" de fact that interfaces and types disappear after transpiling.
  • DIOD: Dependency Injection On Demand: A very opinionated and lightweight (under 2kB minified and gzipped) inversion of control container and dependency injector for Node.js or browser apps.
    • It uses abstract classes to "hack" de fact that interfaces and types disappear after transpiling.
  • Branded Types in TypeScript