Skip to content

Commit 1fdd53e

Browse files
author
IonutGabi
committed
Fix the conflicts and merge with master
2 parents f72ccc5 + 16b13b8 commit 1fdd53e

13 files changed

Lines changed: 128 additions & 70 deletions

File tree

02-languages/02-apuntes/02-typescript/102 interfaces.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ pos.lat = 3.4567; // [ts] Cannot assign to 'lat' because it is a read-only prope
6060
// por ejemplo:
6161

6262
interface Address {
63-
zipCode: number;
64-
city: string;
6563
street: string;
64+
zip: number;
65+
city: string;
6666
}
6767

6868
interface Coord {
@@ -75,19 +75,19 @@ const place: Coord = {
7575
lat: 3.3112,
7676
lon: 5.1123,
7777
address: {
78-
city: "Málaga",
7978
street: "Héroes de Sostoa",
80-
zipCode: 29002,
79+
zip: 29002,
80+
city: "Málaga",
8181
},
8282
};
8383

8484
// También es frecuente utilizar la extensión de interfaces como método de composición. Es decir,
8585
// una interfaz puede extender de otra para combinar propiedades:
8686

8787
interface Address {
88-
zipCode: number;
89-
city: string;
9088
street: string;
89+
zip: number;
90+
city: string;
9191
}
9292

9393
interface Coord {
@@ -103,9 +103,9 @@ const place: Place = {
103103
lat: 3.3112,
104104
lon: 5.1123,
105105
address: {
106-
city: "Málaga",
107106
street: "Héroes de Sostoa",
108-
zipCode: 29002,
107+
zip: 29002,
108+
city: "Málaga",
109109
},
110110
};
111111

@@ -115,9 +115,9 @@ interface Place extends Coord, Address {}
115115
const place: Place = {
116116
lat: 3.3112,
117117
lon: 5.1123,
118-
city: "Málaga",
119118
street: "Héroes de Sostoa",
120-
zipCode: 29002,
119+
zip: 29002,
120+
city: "Málaga",
121121
};
122122

123123
// *** Duck typing ********************************************************************************

02-languages/02-apuntes/02-typescript/103 functions.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///-- FUNCIONES ***********************************************************************************
22

33
// Tipar una función en TypeScript no es más que especificar los tipos de los argumentos que recibe
4-
// y el tipo del valor que devuelve. Es importante tener en cuenta que aquellos argumentos que
4+
// y el tipo del valor que devuelve. Es importante tener en cuenta que aquellos parámetros que
55
// especifiquemos serán obligatorios, a menos que usemos un modificador de opcionalidad:
66

77
// Veamos un primer ejempo con funciones clásicas:
@@ -60,41 +60,55 @@ const shout: ShoutFunction = (text, upperCase = true) =>
6060
console.log(shout("hi"));
6161

6262

63+
// OPCIONAL: Reusando tipados de función con alias
64+
65+
type TextModifierFn = (text: string, modifier?: boolean) => string;
66+
67+
const shout: TextModifierFn = (text, upperCase = false) =>
68+
(upperCase ? text.toUpperCase() : text) + "!!!";
69+
70+
const hyphenize: TextModifierFn = (text, snake = false) => text.replace(" ", snake ? "_" : "-");
71+
72+
console.log(shout("hello world", true)); // HELLO WORLD!!!
73+
console.log(hyphenize("hello world")); // hello-world
74+
console.log(hyphenize("hello world", true)); // hello_world
75+
76+
6377
// *** Funciones como argumentos ******************************************************************
6478

6579
// En el caso de pasar funciones como argumentos de otras, podemos tipar en línea dichos argumentos
6680
// del siguiente modo:
6781

68-
const shout = (text: string, getNumExclamation: () => number): string =>
69-
text.toUpperCase() + "!".repeat(getNumExclamation());
82+
const shout = (text: string, exclamationCallback: () => string) =>
83+
text.toUpperCase() + exclamationCallback();
7084

71-
const getRandom = () => Math.ceil(Math.random() * 10); // Este es mi callback.
85+
const exclamationGenerator = () => "!".repeat(Math.ceil(Math.random() * 10)); // Callback
86+
87+
console.log(shout("WoooW", exclamationGenerator));
88+
console.log(shout("WoooW", exclamationGenerator));
89+
console.log(shout("WoooW", exclamationGenerator));
90+
console.log(shout("WoooW", exclamationGenerator));
7291

73-
console.log(shout("WoW", getRandom));
74-
console.log(shout("WoW", getRandom));
75-
console.log(shout("WoW", getRandom));
76-
console.log(shout("WoW", getRandom));
77-
console.log(shout("WoW", getRandom));
78-
console.log(shout("WoW", getRandom));
7992

8093

8194
// *** Sobrecarga de funciones ********************************************************************
8295

83-
function switchType(c: string): number;
84-
function switchType(c: number): string;
85-
function switchType(c: any) {
86-
if (typeof c === "string") {
87-
return Number(c);
88-
} else {
89-
return String(c);
90-
}
96+
function switchType(arg: number): string;
97+
function switchType(arg: string): number;
98+
function switchType(arg: string | number): string | number {
99+
if (typeof arg === "string") return Number(arg);
100+
else return String(arg);
91101
}
92102

93-
const r1 = switchType(3);
94-
const r2 = switchType("65");
95-
const r3 = switchType({}); // [ts] Argument of type '{}' is not assignable to parameter of type 'number'
103+
const result1 = switchType("105");
104+
console.log(result1, typeof result1);
105+
106+
const result2 = switchType(105);
107+
console.log(result2, typeof result2);
96108

97-
// ⚠ Es posible sobrecargar funciones con diferente número de argumentos.
109+
switchType({});
110+
// ^^^ [ts] 1/2 Argument of type '{}' is not assignable to parameter of type 'number'
111+
// ^^^ [ts] 2/2 Argument of type '{}' is not assignable to parameter of type 'string'
98112

99113

100114
// *** Tipando funciones con interfaces ***********************************************************

02-languages/02-apuntes/02-typescript/106 advanced types.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,7 @@ const day: WorkingDay = "sunday"; // TS error: '"sunday"' is not assignable to t
249249

250250
// También es aplicable a números literales:
251251
type Dice = 1 | 2 | 3 | 4 | 5 | 6;
252-
const throwDice = (): Dice => {
253-
const randomNum = Math.ceil(Math.random() * 6);
254-
return (randomNum !== 0 ? randomNum : 1) as Dice;
255-
// return 6; // Dado trucado MUAHAHAHAHA.
256-
};
252+
const throwDice = (): Dice => Math.floor(Math.random() * 6 + 1) as Dice;
257253

258254

259255
// *** TEMPLATE LITERALS ************************
@@ -275,28 +271,20 @@ type MyDayWithScale = `${DayMood} ${WorkingDay} - Level ${1 | 2 | 3}`;
275271
// tipo concreto:
276272

277273
// -- Caso Base --
278-
interface Week {
279-
monday: string;
280-
tuesday: string;
281-
wednesday: string;
282-
thursday: string;
283-
friday: string;
284-
saturday: string;
285-
sunday: string;
274+
interface Person {
275+
name: string;
276+
age: number;
277+
adult: boolean;
286278
}
287-
type Day = keyof Week;
279+
type PersonKey = keyof Person; // type PersonKey = "name" | "age" | "adult";
288280

289281
// -- Caso Práctico --
290-
const showProps = <O extends object>(obj: O, ...keys: (keyof O)[]): void => {
291-
keys.forEach((key) => console.log(obj[key]));
282+
const showProps = <O extends object>(obj: O, ...keys: (keyof O)[]) => {
283+
keys.forEach(key => console.log(key, obj[key]));
292284
};
293285

294-
const dev = {
295-
type: "frontend",
296-
languages: ["js", "css", "html"],
297-
senior: true,
298-
};
299-
showProps(dev, "type", "languages"); // Check intellisense!;
286+
const javi: Person = { name: "Javi", age: 41, adult: true };
287+
showProps(javi, "adult", "color"); // Check intellisense!;
300288

301289

302290
// *** TIPOS MAPEADOS (MAPPED TYPES) ***************

02-languages/04-playgrounds/02-playground-typescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
},
2727
"scripts": {
2828
"prestart": "npm run transpile && npm run copy",
29-
"start": "concurrently \"npm:transpile -- -w\" npm:devserver",
29+
"start": "concurrently \"npm:transpile -- --watch\" npm:devserver",
3030
"copy": "copyfiles --flat src/**/*.{html,css} transpiled",
31-
"transpile": "tsc",
31+
"transpile": "tsc --pretty",
3232
"devserver": "browser-sync start -c bs-config.json"
3333
},
3434
"dependencies": {

02-languages/04-playgrounds/02-playground-typescript/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"compilerOptions": {
33
"lib": ["DOM", "DOM.Iterable", "ESNext"],
4-
"target": "es5",
5-
"module": "esnext",
4+
"target": "ES5",
5+
"module": "ESNext",
6+
// "moduleResolution": "node", // Use node resolution for "undici types" issue
67
"allowJs": true,
78
"outDir": "transpiled"
89
},

04-frameworks/15-astro/04-desplegando-github-io/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Para ello creamos un archivo `.github/workflows/deploy.yml`:
1414

1515
> A tener en cuenta, hay unas acciones específicas para Astro y desplegar en Github Pages, pero no las vamos a usar, vamos a hacerlo a mano.
1616
17+
> Recordatorio hay un plugin de Read Hat para VSCode para darle soporte a YML.
18+
1719
_.github/workflows/deploy.yml_
1820

1921
```yml

04-frameworks/15-astro/07-contenido-dinamico/readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ _./src/pages/about.astro_
123123

124124
- <p>Aquí iría tu BIO</p>
125125
<p>Here are a few facts about me:</p>
126+
+ <p>Sobre mi:</p>
126127
+ <ul>
127128
+ <li>Me llamo {identity.firstName}.</li>
128129
+ <li>vivo en {identity.country} y trabajo como {identity.occupation}.</li>
@@ -138,7 +139,8 @@ _./src/pages/about.astro_
138139
</html>
139140
```
140141

141-
También esto soporta rendering condicional como en React:
142+
143+
También tenemos soporte para rendering condicional como en React:
142144

143145
_./src/pages/about.astro_
144146

@@ -186,7 +188,7 @@ npm install --save-dev prettier-plugin-astro
186188

187189
- Crear un fichero `.prettierrc` en la raíz del proyecto con el siguiente contenido:
188190

189-
\__.prettierrc_
191+
_.prettierrc_
190192

191193
```json
192194
{
@@ -211,3 +213,5 @@ module.exports = {
211213
plugins: [require("prettier-plugin-astro")],
212214
};
213215
```
216+
217+
> Ojo si no ten funciona, asegurate que tienes abierto el proyecto en la carpeta raíz donde está el fichero `.prettierrc`, tambíen prueba a recargar las pestañas.

04-frameworks/15-astro/08-estilado-con-scope/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ y
7070

7171
Vamos a probarlo
7272

73+
```bash
7374
npm run dev
75+
```
7476

7577
También podemos sacar los estilos fuera, le metemos el prefijo _.modules_ para que tenga scope
7678
Si lo ponemos sin modules:
@@ -89,7 +91,7 @@ _./src/pages/about.astro_
8991
```diff
9092
---
9193
import type { Identity } from "./about.model.ts";
92-
+ import styles from "./about.css";
94+
+ import styles from "./about.module.css";
9395

9496
const pageTitle = "Acerca de dinámico";
9597
```

04-frameworks/15-astro/10-componentes/readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ import "../styles/global.css";
101101
<h1>Blog</h1>
102102
```
103103

104+
Y en la principal tambien (index), mismos pasos
105+
104106
Vamos a crear un footer:
105107

106108
_./src/components/footer.astro_
@@ -116,8 +118,6 @@ const username = "lemoncode";
116118
</footer>
117119
```
118120

119-
Vamos a importarlo y cambiarlo en la ventana principal
120-
121121
_./src/index.astro_
122122

123123
````diff
@@ -312,3 +312,4 @@ h1 {
312312
+
313313
+ }
314314
```
315+
> Si no ves nada es que está en resolucíon móvil (mira la media query), si lo haces más grande se ve (más adelante implementaremos menú hamburguesa para móvil).

04-frameworks/15-astro/11-ejecutando-js-navegador/readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Vamos a ello.
1010

1111
El menú de cabecera sólo funciona bien si estamos en escritorio, si nos vamos a resolución de móvil, nos haría falta ocultar el menú horizontal y mostrar un menú hamburguesa, para eso nos hace falta JavaScript.
1212

13-
Creamos un componente Hamburguer.
13+
Creamos un componente Hamburguer (la opción del menú con tres lineas)
1414

1515
_./src/components/hamburger.astro_
1616

@@ -123,6 +123,7 @@ h1 {
123123
display: inline-block;
124124
padding: 15px 20px;
125125
}
126+
/* OJO ESTO DENTRO DE LA MEDIA QUERY*/
126127
+ .hamburger {
127128
+ display: none;
128129
+ }

0 commit comments

Comments
 (0)