The Shelf tests have three kinds of user. Someone wrote each shape by copying the one before it.
interface Member {
name: string;
email: string;
}
interface Librarian {
name: string;
emial: string;
desk: number;
}
function contactLine(user: Member): string {
return user.name + " <" + user.email + ">";
}
const librarian: Librarian = { name: "Ben", emial: "ben@example.test", desk: 4 };
contactLine(librarian);
users.ts(17,13): error TS2345: Argument of type 'Librarian' is not assignable to parameter of type 'Member'.
Property 'email' is missing in type 'Librarian' but required in type 'Member'.
The copy has a typing mistake in a field name. The compiler found it only at the call, on line 17. The interface with the mistake compiled, and so did the test data, which repeats the mistake to match.
The field was written twice, so it could be written two ways. Write it once.
extends
One interface can start from another.
interface Member {
name: string;
email: string;
}
interface Librarian extends Member {
desk: number;
}
function contactLine(user: Member): string {
return user.name + " <" + user.email + ">";
}
const librarian: Librarian = { name: "Ben", email: "ben@example.test", desk: 4 };
console.log(contactLine(librarian));
Ben <ben@example.test>
Librarian extends Member says a librarian has every field of a member, and then desk. There is no second email to misspell.
The last line passes a Librarian where a Member is expected, and the compiler accepts it. A librarian has everything a member has. You learned in the Junior track that TypeScript compares fields, and this is the same rule.
extends also checks what you add.
interface Member {
name: string;
cardId: number;
}
interface Guest extends Member {
cardId: string;
}
users.ts(6,11): error TS2430: Interface 'Guest' incorrectly extends interface 'Member'.
Types of property 'cardId' are incompatible.
Type 'string' is not assignable to type 'number'.
A guest cannot be a member and have a different kind of card id. The compiler says so at the place you wrote it.
What a type alias can name
type gives a name to any type. You used it for a union of statuses in the Junior track.
type CardId = string | number;
type FeeCase = [number, string];
type OnSaved = (title: string) => void;
interface Member {
name: string;
cardId: CardId;
}
const ana: Member = { name: "Ana", cardId: "A-17" };
An interface describes one thing: the shape of an object. A union, a tuple and a function type are not object shapes, so they need type.
For an object you can use either. Projects usually pick one habit and keep it. This track uses interface for objects and type for everything else.
Combining with &
& joins two types into one that has the fields of both. It is called an intersection.
interface Loan {
book: string;
dueOn: string;
}
type Saved = { id: number; createdAt: string };
type SavedLoan = Loan & Saved;
const loan: SavedLoan = { book: "Dune", dueOn: "2026-04-01", id: 7, createdAt: "2026-03-01" };
console.log(loan.id + ": " + loan.book);
7: Dune
This is useful for fields that many shapes share, such as the id and createdAt that a server adds to everything it saves.
The conflict that & hides
Now join two types that disagree about a field.
type FromApi = { id: string; book: string };
type FromTable = { id: number; row: number };
type Combined = FromApi & FromTable;
const loan: Combined = { id: 7, book: "Dune", row: 2 };
loans.ts(5,26): error TS2322: Type 'number' is not assignable to type 'never'.
Read where the error is. Line 3, which builds the impossible type, has no error. The error is on line 5, at the first object, and it mentions a type called never.
never is the type with no values. An id that is text and also a number cannot exist, so its type is never, and nothing fits it. extends reported the same conflict at the place you wrote it. & accepts it and lets you find out later.
When you see never in an error, look for two types that were joined and disagree.
Remember this
extends builds one interface from another and reports a field that conflicts. type names anything, including unions, tuples and function types. & joins the fields of two types, and when they disagree it makes a field nothing can fit. Write each field in one place.
Reference: Differences Between Type Aliases and Interfaces in the TypeScript Handbook.