Roteiro

Roteiro

  • Basic Types
  • Variable Declarations
  • Interfaces
  • Classes
  • Functions
  • Generics
  • Enums
  • Type Inference
  • Type Compatibility
  • Advanced Types
  • Symbols
  • Iterators and Generators
  • Modules
  • Namespaces
  • Decorators

História

Características

Quem usa

Instalação

Observação

Basic Types

let isDone: boolean = false;

Boolean

let decimal: number = 6;
let hex: number = 0xf00d;
let binary: number = 0b1010;
let octal: number = 0o744;

Number

let color: string = "blue";
color = 'red';

String

let fullName: string = `Bob Bobbington`;
let age: number = 37;
let sentence: string = `Hello, my name is ${ fullName }.

I'll be ${ age + 1 } years old next month.`
let list: number[] = [1, 2, 3];

Array

let list: Array<number> = [1, 2, 3];
let list: number[] = [1, 2, 3];

Array

let list: Array<number> = [1, 2, 3];
// Declare a tuple type
let x: [string, number];

// Initialize it
x = ["hello", 10]; // OK

// Initialize it incorrectly
x = [10, "hello"]; // Error

Tuplas

// OK
console.log(x[0].substr(1));

// Error, 'number' does not have 'substr'
console.log(x[1].substr(1));
enum Color {Red, Green, Blue};
let c: Color = Color.Green;

Enum

// OK
console.log(x[0].substr(1));

// Error, 'number' does not have 'substr'
console.log(x[1].substr(1));

Variable Declarations

var, let and const

Mini curso de Typescript

By Gilson Filho

Mini curso de Typescript

Mini-curso de Typescript ministrado para as equipes de desenvolvimento da BASIS

  • 583