Skip to content

Commit 5fd0db0

Browse files
committed
feat: update all topics
1 parent 0b2b4af commit 5fd0db0

File tree

7 files changed

+111
-3
lines changed

7 files changed

+111
-3
lines changed

typescript/class.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
class SimpleClass {
2+
prop1 : string;
3+
prop2 : number;
4+
prop3 : number[];
5+
}
6+
7+
let sc = new SimpleClass();
8+
sc.prop1 = 'text';
9+
sc.prop2 = 123;
10+
sc.prop3 = [1, 2, 3];
11+
112
class TypeScript {
213
version: string;
14+
public publicProp: string;
15+
private privateProp: string;
16+
protected protectedProp: number;
17+
readonly readonlyProp: number;
318

419
constructor(version: string) {
520
this.version = version;
@@ -54,7 +69,6 @@ test.secondFunc("test");
5469
console.log(test.prop2);
5570

5671

57-
5872
// Using abstract classes.
5973
abstract class MyAbstractClass {
6074
abstract firstFunc(): void;

typescript/guard.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function ex(x: number | boolean) {
44
}
55

66
return x;
7-
}
7+
}
88

99
class MyFirstClass {
1010
prop1 = "One";
@@ -16,7 +16,7 @@ class MySecondClass {
1616
prop2 = "Four";
1717
}
1818

19-
function test(result: MyFirstClass | MySecondClass): object {
19+
function simpleTest(result: MyFirstClass | MySecondClass): object {
2020
if (result instanceof MyFirstClass) {
2121
return {
2222
messageOne: result.prop1 + result.prop2

typescript/interfaces.ts

+45
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,48 @@ const css: Style = {
7373
padding: "1px",
7474
marging: "1px"
7575
}
76+
77+
interface IPerson {
78+
name: string,
79+
fullName?: string,
80+
age: number
81+
}
82+
83+
type PersonType = {
84+
name: string,
85+
fullName?: string,
86+
age: number
87+
}
88+
89+
const firstPerson : PersonType = {
90+
age: 111,
91+
name: 'text'
92+
}
93+
94+
const secondPerson : PersonType = {
95+
age: 222,
96+
name: 'text',
97+
fullName: 'text text'
98+
}
99+
100+
const anotherPerson: IPerson = {
101+
age: 333,
102+
name: 'another text'
103+
}
104+
105+
class SomeSimpleClass {
106+
myProp: string | null;
107+
}
108+
109+
interface IUser extends IPerson {
110+
useFunc(): string,
111+
}
112+
113+
class Employee extends SomeSimpleClass implements IUser {
114+
name: string = 'text';
115+
age: number = 111;
116+
117+
useFunc() {
118+
return `${this.name}${this.age}`;
119+
}
120+
}

typescript/module-1.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const MY_STRING: string = 'text';
2+
export const myFunc = (prop1: string, prop2: number): string => `${prop1}${prop2}`;

typescript/module-2.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { myFunc, MY_STRING } from './module-1';
2+
3+
const result = myFunc(MY_STRING, 123);
4+
console.log(result);

typescript/object.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
let anyObject: any = {
2+
prop1: 'text',
3+
prop2: 111,
4+
};
5+
6+
anyObject = 122;
7+
anyObject = 'helloworld';
8+
9+
let typeObject: { prop1: string, prop2: number } = {
10+
prop1: 'text',
11+
prop2: 333,
12+
};
13+
14+
// Error
15+
// typeObject.prop1 = 123;
16+
17+
typeObject.prop1 = 'new text';
18+
19+
type Person = {
20+
name: string | null,
21+
age: number,
22+
fullName?: string,
23+
gretting?: () => string,
24+
};
25+
26+
let personObject: Person = {
27+
name: 'text',
28+
age: 1,
29+
}
30+
31+
let personNullObject: Person = {
32+
name: null,
33+
age: 1,
34+
}

typescript/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ const secondArray: Array<number> = [1, 2, 3];
66
const words: string[] = ["Hello", "TypeScript", "!"];
77
const typle: [string, number] = ["Hello", 123];
88

9+
typeof 42; // "number"
10+
typeof 'str'; // "string"
11+
typeof true; // "boolean"
12+
typeof []; // "object"
13+
typeof {}; // "object"
14+
typeof null; // "object"
15+
typeof undefined; // "undefined"
16+
typeof Symbol(); // "symbol"
17+
918
let variable: any = 123;
1019
variable = "123";
1120
variable = [1, 2, 3];

0 commit comments

Comments
 (0)