Course contentsShow
← JavaScript
Lesson 2613 of 2,72353. Type Safety Without TypeScriptFree lesson

Object Type Shapes with Inline Syntax

Define object structures inline using JSDoc's object literal syntax for precise shape documentation.

Object Type Shapes with Inline Syntax

What you'll learn: How to define the exact structure of an object using JSDoc's inline object literal notation for richer type documentation.

What This Means

You've already used @type and @param to document simple types like string or number. But what if a parameter or variable is an object with specific properties? JSDoc lets you describe the entire "shape" of that object inline, listing each property name and its type right in the annotation.

This is like giving someone a blueprint: instead of saying "this is a box," you specify "this box has a width (number), a height (number), and a label (string)."

The Syntax

Use curly braces {} inside your type annotation, with property names followed by colons and their types:

/**
 * @param {{name: string, age: number, active: boolean}} user
 */
function greetUser(user) {
  console.log(`Hello, ${user.name}. Age: ${user.age}`);
}

greetUser({ name: 'Alice', age: 30, active: true }); // Matches shape

Why This Matters

Without this, you'd just write @param {object} user, which tells readers nothing about what properties exist. The inline syntax documents the contract: editors can autocomplete property names, and linters can warn if you pass the wrong shape.

You can nest objects too:

/**
 * @type {{city: string, coordinates: {lat: number, lon: number}}}
 */
const location = { city: 'Oslo', coordinates: { lat: 59.9, lon: 10.7 } };

Key Takeaway: Inline object syntax in JSDoc lets you define precise property shapes directly in annotations, giving tools and teammates a clear structure to validate against—no TypeScript required.