Javascript - Typescript

About

TypeScript is a typed superset of JavaScript that compile to plain JavaScript. It adds static typing.

You can also get the goodies if you declare your type in the JSdoc (Reference)

Basic

See Typescript - tsc (official compiler)

When installing third party libraries (lodash, jQuery, …), it is important to remember to install the typing definition for that library.

JQuery

  • Add Jquery as package dependency (because it's already available we declare it as peer dependency)
yarn add @types/jquery --dev
yarn add jquery --peer
  • Add it to the compile path
{
  "compilerOptions": {
....
    "types": [
      "jquery"
    ]
  },
...
}

Scope

Feature

Type

type annotation. See Typescript - Type

Enum

export enum choice {
  YES = 'Yes',
  NO = 'No',
  NA = 'Not applicable',
}

Interface

interface are type

Cast

Class

Classes in TypeScript are just a shorthand for the same prototype-based OO.

Typescript - Class

Support

Cannot find name 'name'.ts(2304)

The name is not imported you can define it also fully.

Example:

* @param {!Browser} browser

could be replaced with the fully qualified name

* @param {!import('puppeteer').Browser} browser

Powered by ComboStrap