viernes, 4 de febrero de 2022

Tipos básicos de typescript

 //boolean

let muted: boolean = true;

muted = false;

//numeros
let age = 6;
let numerador: number = 42;
let denominador: number = age;
let resultado = numerador / denominador;

//string
let nombre: string = 'richard';
let saludo = `me llamo ${nombre}`;

//arreglos
let people: string[] = [];
people = ["isabel","nicole", "raul"];
// people.push("9000")

let peopleAndNumbers: Array< string | number > = []
peopleAndNumbers.push("richi");
peopleAndNumbers.push(9001);

//enum
enum Color {
    Rojo = "rojo",
    Verde = "verde",
    Azul = "azul",
}
let colorFavorito: Color = Color.Verde
console.log(`mi color favorito es ${colorFavorito}`);

//any

let comodin: any = "joker"
comodin = { type: 'wildcard' };

//object
let someObject: object = { type: 'wildcard' };

No hay comentarios:

Publicar un comentario

Blogs Colombia