Skip to content

Commit 9dc3a09

Browse files
Aryan JabbariAryan Jabbari
authored andcommitted
Add TypeScript crash course
1 parent 45f255d commit 9dc3a09

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

doczrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
2-
menu: ['Home', 'Installation', 'Examples'],
2+
menu: ['Home', 'TypeScript Crash Course', 'Installation', 'Examples'],
33
themeConfig: {
44
colors: { primary: '#294E80' },
55
},
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: TypeScript Crash Course
3+
route: /typescript-crash-course
4+
---
5+
6+
# TypeScript Crash Course
7+
8+
This is meant to be a basic introduction to common types used in TypeScript. This is not necessarily releated to React but will be used as React files are typed.
9+
10+
```typescript
11+
const myName: string = 'Aryan';
12+
const myAge: number = 25; // I swear 🤥:
13+
14+
// array of type
15+
const myFavoriteLanguages: string[] = ['JavaScript', 'Python', 'Java'];
16+
17+
// string literals (must be one of these EXACT values)
18+
const seasons: 'summer' | 'fall' | 'winter' | 'spring' = 'winter';
19+
20+
// object with specific properties
21+
const car: {
22+
make: string;
23+
model: string;
24+
yearReleased: number;
25+
hasAirbags?: boolean; // the question mark means this property is optional
26+
} = {
27+
make: 'Honda',
28+
model: 'Civic',
29+
yearReleased: 1994,
30+
}; // fun fact, this was my first car!
31+
32+
// you can also define the type separately
33+
type Car = {
34+
make: string;
35+
model: string;
36+
yearReleased: number;
37+
hasAirbags?: boolean;
38+
};
39+
const someFancierCar: Car = {
40+
make: 'Jaguar',
41+
model: 'XJ',
42+
yearReleased: 2019,
43+
hasAirbags: true,
44+
};
45+
46+
// array of objects
47+
const garage: Car[] = [car, someFancierCar];
48+
49+
// function without call signature
50+
const callback: Function = () => 'ohai!';
51+
52+
// function with call signature
53+
const callbackWithStrictSignature: (name: string) => string = () => `hai again, ${name}!`;
54+
```

0 commit comments

Comments
 (0)