Skip to content

Object types

Goal: Declare object shapes with the type brace form.

SJS uses type Name { ... } for structural types. Conformance is checked structurally — no implements keyword.

Example

type Point {
  x: number;
  y: number;
}

type Named {
  name: string;
}

type Place extends Named {
  city: string;
}

function label(p: Place): string {
  return p.name + " @ " + p.city
}

Open in playground

Key takeaways

  • Members end with semicolons.
  • extends composes object types.
  • Classes satisfy object types implicitly.

Next: Generics

Documentation