-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agrego nuevos apunte a fundamentos de typescript
- Loading branch information
Showing
5 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Curso-de-Fundamentos-de-TypeScript/src/type-array-tuple.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Explicito | ||
let users: string[]; | ||
|
||
users = ['Colombia', 'Mexico', 'Argentina', 'España']; | ||
// users = [1, true, 'test']; // Error tipo de dato | ||
|
||
//Inferidos | ||
let otherUser = ['Colombia', 'Mexico', 'Argentina', 'España']; | ||
// otherUser = [1, true, 'test'];// Error tipo de dato | ||
|
||
//Array<TIPO> | ||
let pictureTitles: Array<string>; | ||
|
||
pictureTitles = ['Atardecer', 'Vacation Time', 'Landscape']; | ||
|
||
//Accediendo a los valores de un Array | ||
console.log('first user:', users[0]); | ||
console.log('first title:', pictureTitles[0]); | ||
|
||
// Propiedades en Array | ||
// Tamaño del arreglo | ||
console.log('El tamaño del arreglo es:', users.length); | ||
//Agregar nuevo dato | ||
users.push('Peru'); | ||
users.sort(); | ||
console.log('users:', users); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Orientacion para fotografias | ||
// const landscape = 0; | ||
// const potrait = 1; | ||
// const squate = 2; | ||
// const panorama = 3; | ||
|
||
enum PhotoOrientation { | ||
Landscape = 0, | ||
Portrait = 1, | ||
Square = 2, | ||
Panorama = 3, | ||
} | ||
|
||
const landscape: PhotoOrientation = PhotoOrientation.Landscape; | ||
console.log({ landscape }); // landscape: 0 | ||
console.log('landscape', PhotoOrientation[landscape]); // landscape Landscape | ||
|
||
enum PictureOrientation { | ||
Landscape = 10, | ||
Portrait, // 11 | ||
Square, // 12 | ||
Panorama, // 13 | ||
} | ||
console.log('portrait', PictureOrientation.Portrait); // 11 | ||
|
||
enum Country { | ||
Bolivia = 'bol', | ||
Colombia = 'col', | ||
Mexico = 'mex', | ||
UnitedState = 'usa', | ||
España = 'esp', | ||
} | ||
|
||
const country: Country = Country.Colombia; | ||
console.log({ country }); // col |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let user: object; | ||
user = {}; | ||
|
||
user = { | ||
id: 1, | ||
username: 'Mooenz', | ||
firstName: 'Jose Manuel', | ||
isPro: true, | ||
}; | ||
|
||
console.log({ user }); | ||
|
||
// console.log(user.username); // Da un error | ||
|
||
//Object vs object (clase Js vs tipo TS) | ||
const myObj = { | ||
//TypeScript considera este objeto como una instancia de Object.prototype | ||
id: 1, | ||
username: 'Mooenz', | ||
firstName: 'Jose Manuel', | ||
isPro: true, | ||
}; | ||
|
||
const isInstance = myObj instanceof Object; // Aqui comprobamos que si es una instancia de Object | ||
console.log(isInstance); // Da true | ||
|
||
console.log(myObj.username); // Muestra usuario |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export {}; | ||
|
||
// [1, 'user'] | ||
let user: [number, string]; | ||
user = [1, 'Mooenz']; | ||
|
||
console.log({ user }); | ||
console.log('id:', user[0]); | ||
console.log('name:', user[1]); | ||
|
||
// Tuplas con varios valores | ||
// id, username, isPro | ||
let userInfo: [number, string, boolean]; | ||
userInfo = [2, 'Mooenz', true]; | ||
console.log({ userInfo }); | ||
|
||
// Arreglo de Tuplas | ||
let array: [number, string][] = []; | ||
array.push([1, 'Mooenz']); | ||
array.push([2, 'Jmanu21']); | ||
array.push([3, 'Jmanuel21']); | ||
console.log({ array }); | ||
|
||
// Uso de funciones Array | ||
// Jmanuel21 => Jmanuel2108 | ||
|
||
array[2][1] = array[2][1].concat('08'); | ||
console.log({ array }); |