Skip to content

Commit 1e5a9cc

Browse files
committed
Update typescript-basics.md
1 parent 848fe3e commit 1e5a9cc

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

TypeScript/Basics/typescript-basics.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ interface IService {
162162
## Classes
163163

164164
- **Modifiers** <br>
165+
_Various modifiers allow you to define the scope of variables and methods_
165166

166167
```ts
167168
class Example {
@@ -182,16 +183,14 @@ class Example {
182183
(not from inherited and outside) */
183184
private secret = "hello";
184185

185-
/* allows access without creating an instance
186-
of the class may be supplemented by modifiers */
187-
static sayHello() {
188-
console.log("Hello!");
189-
}
186+
alert = () => {};
190187
}
191188
```
192189

190+
- **Extending a class** <br>
191+
_Classes can easily be extended by adding new variables/methods. This also supports overriding methods, but in a way that ensures backward compatibility._
192+
193193
```ts
194-
// Extending a class
195194
class NewExmaple extends Example {
196195
constructor(a: number, b: number, c: number) {
197196
super(a, b);
@@ -200,8 +199,43 @@ class NewExmaple extends Example {
200199

201200
c: number;
202201

203-
sayHello(name: string) {
202+
alert(name?: string) {
204203
console.log(`Hello ${name}`);
205204
}
206205
}
207206
```
207+
208+
- **Abstract classes** <br>
209+
_Abstract classes/methods do not allow you to create instances, but only serve for expansion_
210+
211+
```ts
212+
abstract class Somebody {
213+
hello(): void {
214+
console.log("Hello!");
215+
}
216+
}
217+
218+
class User extends Somebody {
219+
introduce(): void {
220+
console.log("I am User!");
221+
}
222+
}
223+
224+
const user = new User();
225+
user.hello(); // "Hello!"
226+
```
227+
228+
- **Interface implementation** <br>
229+
_Interfaces can be used to describe classes_
230+
231+
```ts
232+
interface ITest {
233+
value: string;
234+
getNumber: () => number;
235+
}
236+
237+
class Test implements ITest {
238+
value = "test";
239+
getNumber = () => 7;
240+
}
241+
```

0 commit comments

Comments
 (0)