Hoppa till innehåll

Intersektionstyper

En intersektionstyp är en typ som representerar ett värde som har alla egenskaper hos två eller flera typer. Intersektionstyper betecknas med symbolen & mellan varje typ.

type X = {
a: string;
};
type Y = {
b: string;
};
type J = X & Y; // Intersection
const j: J = {
a: 'a',
b: 'b',
};