Giter Club home page Giter Club logo

course-understanding-typescript's Introduction

Course Understanding Typescript

  • Is a javascript superset
  • A language building up on Javascript
  • Add new features + advantages to javascript
  • Need to be compiled to javascript
  • Compile typescript features to javascript workarounds
  • Typescript only checks before compilation

Instaling and using typescript

npm i -g typescript
tsc fileName.ts
tsc fileName.ts --watch
tsc fileName.ts -w

Para dar watch em todos os arquivos typescript presentes no diretório atual use o comando, o qual criará um arquivo tsconfig.json que representa o arquivo de configuração do typescript (mesmo propósito que o package.json) Com isto é possivel rodar somente tsc -w para dar watch nos arquivos

tsc --init
tsc -w

Typescript Overview

Typescript adds:

  • Types
  • Next-gen Javascript Features (Compiled down for older Browsers)
  • Non-Javascript Features like Interfaces or Generics
  • Meta-Programming Features like Decorators
  • Rich Configuration Options
  • Modern Tooling that helps even in non-Typescript Projects

Core Types

Principal types from Typescript

In Typescript, you work with types like string or number Important: It is string and number (etc.), NOT String, Number, etc. The core primitive types in Typescript are all lowercase!

Core Type: number

All numbers, no differentiation between integers or floats

1, 5.3, -10

Core Type: string

All text values

'Hi'
"Hi"
`Hi`

Core Type: boolean

Just these two, no "truthy" or "falsy" values

true
false

Core Type: object

Any Javascript object, more specific types (type of object) are possible

{
  age: 30
}

Core Type: Array

Any javascript array, type can be flexible or strict (regarding the element types)

[1, 2, 3]

Core Type: Tuple

Added by Typescript: Fixed-length array and fixed type

[1, 2]

Core Type: Enum

Added by Typescript: Automatically enumerated global constant identifiers

enum Type {
  NEW,
  OLD
}

enum Role {
  ADMIN = 5, // 5
  READ_ONLY, // 6
  AUTHOR,    // 7
}

enum File {
  JPG = 100,
  PDF = 200,
  EXE = 300,
}

enum Color {
  RED = 'Red'
  BLUE = 'Blue'
  Yellow = 'Yellow'
}

Core Type: Any

Any kind of value, no especific type assignment

Type Inference

Automatic understands what type a variable have when created with a core type

const number1 = 1
// Same as const number1: number = 1

Compiler

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.