Course contentsShow
← TypeScript
Lesson 292 of 1,7967. ObjectsFree lesson

Function Properties in Object Types

Typing object properties that hold functions using method signature syntax.

Function Properties in Object Types

You'll learn: How to type object properties that store functions using method signature syntax.

Two Ways to Type Function Properties

When an object property holds a function, you have two main syntax options in TypeScript:

Method Signature Syntax (Recommended)

This looks like defining a method in a class:

type Calculator = {
  add(x: number, y: number): number;
  subtract(x: number, y: number): number;
};

const calc: Calculator = {
  add(x, y) {
    return x + y;
  },
  subtract(x, y) {
    return x - y;
  }
};

Property Signature Syntax (Alternative)

This treats the function as a regular property that happens to be callable:

type Calculator = {
  add: (x: number, y: number) => number;
  subtract: (x: number, y: number) => number;
};

When to Use Which?

Method syntax is cleaner and matches how you typically write object methods. It's the standard choice for most cases.

Property syntax is useful when you need to emphasize that a function is just a value being stored, or when dealing with optional function properties.

Think of It Like a Recipe Card

Imagine a recipe card that lists instructions. You can either write "Chop: Cut vegetables into small pieces" (method style) or "Chopping instruction: (how to cut vegetables)" (property style). Both work, but the first reads more naturally.

Key Takeaway: Use method signature syntax methodName(params): returnType for cleaner, more readable object types with function properties—it mirrors how you write the actual methods.