要随时牢记在心中:决心取得成功比任何一件事情都重要。——林肯

分享一个学习typescript练习的开源项目

github:

https://github.com/typescript-exercises/typescript-exercises

网站:

https://typescript-exercises.github.io/

这里有不同的练习,目前是16个,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*

Welcome to:

................................................................
. .
. #################### #################### E .
. #################### #################### X .
. #### #### E .
. #### #### R .
. #### #################### C .
. #### #### I .
. #### #### S .
. #### #################### E .
. #### #################### S .
. .
................................................................

The goal: Let everyone play with many different TypeScript features
and get an overview of TypeScript capabilities and principles.

Things to cover:

1. Basic typing.
2. Refining types.
3. Union types.
4. Merged types.
5. Generics.
6. Type declarations.
7. Module augmentation.
8. Advanced type mapping.

Rules and principles:

1. Avoid using "any" type at all costs.
2. Difficulty quickly grows one exercise after another.
3. Feel free to send pull requests if you've come up
with improvements!
4. Provide feedback to the creator of these exercises.
5. Enjoy.

Brief UI guide:

+--------------------------------------------------------------+
| TypeScript exercises |
+--------------------------------------------------------------+
| Exercises 1·2·3·4... << Navigate through exercises >> |
+---------------+----------------------------------------------+
| Files | file.ts << Filename and status >> |
+---------------+----------------------------------------------+
| file.ts | 1 import {x} from 'y'; |
| dir | 2 |
| sub.ts | 3 |
| | |
| << Current | << Currently selected file code editor >> |
| exercise file | |
| structure >> +----------------------------------------------+
| | |
| | << Errors to fix in order to proceed >> |
| | |
+---------------+----------------------------------------------+

Intro:

We are starting a small community of users. For performance
reasons, we have decided to store all users right in the code.
This way we can provide our developers with more
user-interaction opportunities. With user-related data, at least.
All the GDPR-related issues will be solved some other day.
This would be the basis for our future experiments during
these exercises.

Exercise:

Given the data, define the interface "User" and use it accordingly.

*/

export type User = unknown;

export const users: unknown[] = [
{
name: 'Max Mustermann',
age: 25,
occupation: 'Chimney sweep'
},
{
name: 'Kate Müller',
age: 23,
occupation: 'Astronaut'
}
];

export function logPerson(user: unknown) {
console.log(` - ${user.name}, ${user.age}`);
}

console.log('Users:');
users.forEach(logPerson);


// In case you are stuck:
// https://www.typescriptlang.org/docs/handbook/2/objects.html