interface (TypeScript)
In TypeScript, a named description of an object's shape: which properties it has and their types.
In more detail
An interface lists property names and their types, and a question mark marks a property as optional. TypeScript then reports an error wherever an object does not fit the shape.
Examples
Every lesson starts by declaring one, such as interface Token { $value: string; $type?: string }.Storybook Autodocs reads component prop interfaces to build documentation.interface User { id: string; email: string; isActive: boolean }Related terms
- TypeScript — JavaScript with added type annotations, checked by a compiler before the code runs.
- prop — An input passed to a React component, written like an HTML attribute, such as size="lg" in <Button size="lg">.
- Autodocs — The Storybook feature that builds a documentation page for a component from its stories, TypeScript types and JSDoc comments.
- type alias — A name given to any type with the type keyword, such as type HttpMethod = "GET" | "POST".
- declaration merging — TypeScript combining several declarations with the same name, such as two interface blocks, into one type.
- structural typing — A type rule where two types are compatible if they have the same shape, whatever they are called.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
Taught in
- Design Systems Architecture: Foundations, Layers & Taxonomy — Design Systems & Component Engineering
- Design Tokens: W3C Specs, Global, Semantic & Component Tokens — Design Systems & Component Engineering
- Storybook & Component Driven Development Workflows — Design Systems & Component Engineering
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- Primitive Types: String, Number, Boolean, Bigint And Symbol — Production TypeScript
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Custom Type Predicates: Functions Returning is Type — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Generic Interfaces, Classes And Type Aliases — Production TypeScript
- Generic Constraints: extends, keyof And Indexed Access — Production TypeScript
- Default Generic Arguments And Multi-Type Parameters — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript