Implementation of an Interface (#20815)
* Implementation of an Interface * minor updates
This commit is contained in:
committed by
Christopher McCormack
parent
8ec35afac1
commit
c2022eefbb
@ -26,4 +26,19 @@ Interfaces can contain optional parameters
|
||||
interface User = {
|
||||
email?: string;
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
We can also use interfaces as the Promises to our classes. For example, when declaring names of methods in our interface they need to be in our implementation otherwise we will get an exception.
|
||||
Example:
|
||||
```typescript
|
||||
interface Login {
|
||||
login(): boolean;
|
||||
}
|
||||
class LoginImplementation implements Login {
|
||||
login(): boolean {
|
||||
//Here would be our implementation of login class.In this case it returns an Error.
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user