├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 13.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── boolean.ts ├── null.ts ├── undefined.ts ├── clases.ts ├── objetoLiteral.ts ├── arrays.ts ├── enum.ts ├── string.ts ├── interfaces.ts ├── number.ts ├── types.ts ├── funciones.ts └── README.md /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/1.png -------------------------------------------------------------------------------- /10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/10.png -------------------------------------------------------------------------------- /11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/11.png -------------------------------------------------------------------------------- /12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/12.png -------------------------------------------------------------------------------- /13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/13.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/2.png -------------------------------------------------------------------------------- /3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/3.png -------------------------------------------------------------------------------- /4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/4.png -------------------------------------------------------------------------------- /5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/5.png -------------------------------------------------------------------------------- /6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/6.png -------------------------------------------------------------------------------- /7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/7.png -------------------------------------------------------------------------------- /8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/8.png -------------------------------------------------------------------------------- /9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/HEAD/9.png -------------------------------------------------------------------------------- /boolean.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // BOOLEANS 4 | 5 | // Valor booleano true: 6 | const bool1: boolean = true; 7 | 8 | // Valor booleano false: 9 | const bool2: boolean = false; 10 | 11 | -------------------------------------------------------------------------------- /null.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // NULL 4 | 5 | // Declaración de una variable con valor null 6 | let variablenull: null; 7 | 8 | // Asignación de valor null 9 | variablenull = null; 10 | 11 | -------------------------------------------------------------------------------- /undefined.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // UNDEFINED 4 | 5 | // Declaración de una variable con valor undefined 6 | let variableUndefined: undefined; 7 | 8 | // Asignación de valor undefined 9 | variableUndefined = undefined; 10 | -------------------------------------------------------------------------------- /clases.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // CLASES 5 | 6 | class Persona { 7 | nombre: string; 8 | 9 | constructor(nombre: string) { 10 | this.nombre = nombre; 11 | } 12 | 13 | saludar() { 14 | console.log(`Hola, mi nombre es ${this.nombre}.`); 15 | } 16 | } 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /objetoLiteral.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // OBJETO 5 | 6 | const programador = { 7 | nombre: "Sergie Code", 8 | casado: false, 9 | cursosEnYoutube: 4, 10 | cursos: ['HTML', 'CSS', 'JAVASCRIPT', 'REACT'], 11 | viajeAEuropa: undefined, 12 | viajeAEstadosUnidos: null 13 | }; 14 | 15 | 16 | -------------------------------------------------------------------------------- /arrays.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // ARRAYS 5 | 6 | // Arreglo de números: 7 | const numeros: number[] = [1, 2, 3, 4, 5]; 8 | 9 | // Arreglo de cadenas de texto: 10 | const nombres: string[] = ["Juan", "María", "Pedro"]; 11 | 12 | // Arreglo de booleanos: 13 | const valoresBool: boolean[] = [true, false, true]; 14 | 15 | //etc (ya los veremos) 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /enum.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // ENUM 4 | 5 | // Definición de un enum para días de la semana 6 | enum DiasSemana { 7 | Lunes, 8 | Martes, 9 | Miércoles, 10 | Jueves, 11 | Viernes, 12 | Sábado, 13 | Domingo, 14 | } 15 | 16 | 17 | // Enum con valores de cadena (String Enums): 18 | enum Colores { 19 | Rojo = "rojo", 20 | Verde = "verde", 21 | Azul = "azul", 22 | } 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /string.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // STRING 4 | 5 | // Comillas dobles: 6 | const str1: string = "Hola, soy una cadena con comillas dobles."; 7 | // Comillas simples: 8 | const str2: string = 'Hola, soy una cadena con comillas simples.'; 9 | 10 | // Template literals (backticks): 11 | const nombre: string = 'Juan'; 12 | const edad: number = 30; 13 | 14 | const str3: string = `Hola, mi nombre es ${nombre} y tengo ${edad} años.`; 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /interfaces.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // INTERFACES 4 | 5 | // Interface básica: 6 | interface Persona { 7 | nombre: string; 8 | edad: number; 9 | } 10 | 11 | // Interface con propiedades opcionales: 12 | interface Producto { 13 | nombre: string; 14 | precio: number; 15 | descripcion?: string; 16 | } 17 | 18 | // Interface para funciones: 19 | interface Comparador { 20 | (a: number, b: number): boolean; 21 | } 22 | 23 | // Interface para clases (class interfaces): 24 | interface Persona { 25 | nombre: string; 26 | edad: number; 27 | saludar(): void; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /number.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // NUMEROS 4 | 5 | // Números enteros: 6 | const num1: number = 10; 7 | 8 | // Notación exponencial: 9 | const num3: number = 2.5e3; // 2.5 * 10^3 = 2500 10 | 11 | // Notación exponencial negativa: 12 | const num4: number = 1.5e-2; // 1.5 * 10^-2 = 0.015 13 | 14 | // Hexadecimales (base 16) utilizando el prefijo "0x": 15 | const num5: number = 0xA; // Valor decimal: 10 16 | 17 | // Octales (base 8) utilizando el prefijo "0o": 18 | const num6: number = 0o12; // Valor decimal: 10 19 | 20 | // Binarios (base 2) utilizando el prefijo "0b": 21 | const num7: number = 0b1010; // Valor decimal: 10 22 | 23 | 24 | -------------------------------------------------------------------------------- /types.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | // TYPES 4 | 5 | 6 | // Type básico: 7 | type Numero = number; 8 | 9 | // Type básico Objeto Literal: 10 | type Persona1 = { 11 | nombre: string; 12 | edad: number; 13 | } 14 | 15 | // Type con union types: 16 | type Nombre = string | null; 17 | 18 | // Type con propiedades opcionales: 19 | type Producto1 = { 20 | nombre: string; 21 | precio: number; 22 | descripcion?: string; 23 | } 24 | 25 | // Type para funciones: 26 | type Comparador1 = { 27 | (a: number, b: number): boolean; 28 | } 29 | 30 | // Type para clases (class Types): 31 | type Persona2 = { 32 | nombre: string; 33 | edad: number; 34 | saludar(): void; 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /funciones.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // FUNCIONES 5 | 6 | // Declaración de función con tipado explícito: 7 | function sumar(a: number, b: number): number { 8 | return a + b; 9 | } 10 | 11 | // Funciones flecha con retorno implícito (inferido por TypeScript): 12 | const dividir = (a: number, b: number) => a / b; 13 | 14 | // Funciones con parámetros opcionales: 15 | function saludar(nombre: string, edad?: number): string { 16 | if (edad !== undefined) { 17 | return `Hola, mi nombre es ${nombre} y tengo ${edad} años.`; 18 | } else { 19 | return `Hola, mi nombre es ${nombre}.`; 20 | } 21 | } 22 | 23 | // Funciones con parámetros por defecto: 24 | function saludar2(nombre: string, edad: number = 30): string { 25 | return `Hola, mi nombre es ${nombre} y tengo ${edad} años.`; 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tipo de datos en TYPESCRIPT: 2 | 3 | Link al curso completo en Youtube: 4 | [TYPESCRIPT DESDE CERO POR SERGIE CODE](https://youtu.be/UTA5bykCx2c) 5 | 6 | ![tipo de datos typescript](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/1.png) 7 | 8 | ![typescript](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/2.png) 9 | 10 | ![typescript](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/3.png) 11 | 12 | ![4](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/4.png) 13 | 14 | ![5](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/5.png) 15 | 16 | ![6](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/6.png) 17 | 18 | ![7](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/7.png) 19 | 20 | ![8](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/8.png) 21 | 22 | ![9](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/9.png) 23 | 24 | ![10](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/10.png) 25 | 26 | ![11](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/11.png) 27 | 28 | ![12](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/12.png) 29 | 30 | ![13](https://raw.githubusercontent.com/sergiecode/tipo-de-datos-en-typescript/master/13.png) 31 | 32 | --------------------------------------------------------------------------------