Skip to content

Commit 7832dcf

Browse files
committed
Adds new nice snippets
1 parent f354bf9 commit 7832dcf

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

example-snippets/aliases.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
console.clear();
2+
3+
type Point = {
4+
x: number;
5+
y: number;
6+
message: string;
7+
};
8+
9+
function printCoord(point: Point) {
10+
console.log(`The coordinate's x value is ${point.x}.`);
11+
console.log(`The coordinate's y value is ${point.y}.`);
12+
console.log(`The message is: ${point.message}!`);
13+
}
14+
15+
const infos = {
16+
x: 42,
17+
y: 23,
18+
message: "De amor nadie se muere",
19+
};
20+
21+
printCoord(infos);

example-snippets/interfaces.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
console.clear();
2+
3+
interface IPlayerProfile {
4+
name: string;
5+
age: number;
6+
teams: string[];
7+
jerseyNumber: number[] | number;
8+
goatStatus: boolean;
9+
}
10+
11+
function playerProfile(infos: IPlayerProfile) {
12+
const isGoat = infos.goatStatus === true ? "Yeah" : "MJ is the GOAT";
13+
14+
console.log(
15+
`
16+
- Name: ${infos.name}
17+
- Age: ${infos.age}
18+
- Teams: ${infos.teams}
19+
- Jersey number: ${infos.jerseyNumber}
20+
- G.O.A.T. status: ${isGoat}
21+
`,
22+
);
23+
}
24+
25+
const lebronData = {
26+
name: "Lebron Raymone James Sr.",
27+
age: new Date().getFullYear() - 1984,
28+
teams: ["Cavaliers", "Heat", "Cavaliers", "Lakers"],
29+
jerseyNumber: [23, 6],
30+
goatStatus: true,
31+
};
32+
33+
playerProfile(lebronData);

example-snippets/unions.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
console.clear();
22

33
function printId(id: number | string) {
4-
console.log(`This is your identification: ${id} (type: ${typeof id}).`);
4+
if (typeof id === "string") {
5+
return console.log(
6+
`O narrowing foi pra string, então posso usar o .toUpperCase(): ${id.toUpperCase()}`,
7+
);
8+
}
9+
10+
return console.log(`Timeline sem narrowing: ${id}`);
511
}
612

7-
// printId("Comitê Revolucionário Ultrajovem");
8-
// printId(42);
13+
function welcomePeople(guest: string[] | string) {
14+
if (Array.isArray(guest)) {
15+
return console.log(
16+
`Fala, galera: ${guest.join(" and ")} e o restante do pessoal!`,
17+
);
18+
}
919

10-
function unionsRestrictions(name: string | number) {
11-
return name.length;
20+
return console.log(`Boas-vindas, ${guest.toUpperCase()}. Mesa para um?`);
1221
}
1322

14-
unionsRestrictions("Lúthien Tinúviel");
23+
printId("Comitê Revolucionário Ultrajovem");
24+
printId(42);
25+
26+
welcomePeople(["Yavanna", "Manwë", "Oromë"]);
27+
welcomePeople("Círdan");

0 commit comments

Comments
 (0)