0 of 6 problems solved0%
2 of 6

Alias and Interface Fit

TypeScript cares about shape. If two declarations have the same properties with the same types, they fit. It does not matter whether one was declared with type and the other with interface.

interface Coord {
  x: number;
  y: number;
}
type Point = { x: number; y: number };

You will define both forms for a person and write a small function that works with the interface and accepts a value from the alias.

Your Task

Compute the length of a full name.

  • Create type PersonAlias = { first: string; last: string }.
  • Create interface Person { first: string; last: string }.
  • Implement nameLength(p: Person): number that returns first.length + last.length + 1 (for the space).
  • In tests, pass an object of the alias shape to nameLength.