Method Shorthand vs Function Properties
You'll learn: How to write object methods two different ways in TypeScript — and why the difference matters for this binding.
Two Ways to Write the Same Thing
When you define a function inside an object type, TypeScript gives you two syntaxes that look nearly identical but behave differently:
type Calculator = {
// Method shorthand syntax
add(a: number, b: number): number;
// Function property syntax
subtract: (a: number, b: number) => number;
};
Both describe a function that takes two numbers and returns a number. But there's a subtle difference.
The Key Difference: this Binding
Method shorthand (methodName(): ReturnType) is designed for traditional object methods. It expects the function to be called as a method with a this context.
Function properties (propertyName: () => ReturnType) describe properties that happen to hold functions. They don't make assumptions about this.
Think of it like this: method shorthand is for "verbs the object can do" (actions), while function properties are for "functions the object carries" (data that happens to be callable).
type Logger = {
log(message: string): void; // "This object can log"
formatter: (text: string) => string; // "This object has a formatter"
};
In practice, method shorthand is the conventional choice for typical object methods. Function properties appear more often when you're storing callbacks or when you explicitly want arrow functions (which preserve this from their creation context).
Key Takeaway: Use methodName(): Type for regular methods; use propertyName: () => Type when treating functions as stored values or when this binding differences matter.