Can you extend (inherit) types in TypeScript?
Hello everyone! I just started learning TypeScript and ran into a problem. I have an interface for basic user data:
```typescript
interface User {
id: number;
name: string;
email: string;
}
```
Now I need to create a type for an admin that has all the fields of a regular user, but also a role and permissions. I know that interfaces can be extended using `extends`, but does this work for types declared with `type`?
I tried doing this:
```typescript
type User = {
id: number;
name: string;
email: string;
}
type Admin = User & {
role: string;
permissions: string[];
}
```
It worked, but I was told that this is not exactly "extension", but type intersection. What's the difference? And is there a way to do
No answers yet.
Log in to leave an answer