Javascript - Typescript

1 - 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)

3 - 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.

4 - 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"
    ]
  },
...
}

5 - Scope

6 - Feature

6.1 - Type

type annotation. See Typescript - Type

6.2 - Enum


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

6.3 - Interface

interface are type

6.4 - Cast

Typescript - Type Cast (Coercion)

6.5 - Class

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

Typescript - Class

7 - Support

7.1 - 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


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap