objectShorthand
Object property and method definitions can use shorthand syntax when the key matches the value identifier or when a function expression is assigned.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
ES2015 introduced shorthand syntax for object literals, allowing more concise property and method definitions. When a property value is an identifier with the same name as the property key, or when a function expression is assigned to a property, shorthand syntax can be used.
Examples
Section titled “Examples”Property Shorthand
Section titled “Property Shorthand”const const name: "Alice"
name = "Alice";const const user: { name: string;}
user = { name: string
name: const name: "Alice"
name };const const value: 42
value = 42;const const settings: { value: number; other: boolean;}
settings = { value: number
value: const value: 42
value, other: boolean
other: true };const const name: "Alice"
name = "Alice";const const user: { name: string;}
user = { name: string
name };const const value: 42
value = 42;const const settings: { value: number; other: boolean;}
settings = { value: number
value, other: boolean
other: true };Method Shorthand
Section titled “Method Shorthand”const const config: { handler: () => string;}
config = { handler: () => string
handler: function () { return "result"; },};const const service: { load: () => Promise<string>;}
service = { load: () => Promise<string>
load: async function () { return await var Promise: PromiseConstructor
Represents the completion of an asynchronous operation
Promise.PromiseConstructor.resolve<string>(value: string): Promise<string> (+2 overloads)
Creates a new resolved promise for the provided value.
resolve("data"); },};const const config: { handler(): string;}
config = { function handler(): string
handler() { return "result"; },};const const service: { load(): Promise<string>;}
service = { async function load(): Promise<string>
load() { return await var Promise: PromiseConstructor
Represents the completion of an asynchronous operation
Promise.PromiseConstructor.resolve<string>(value: string): Promise<string> (+2 overloads)
Creates a new resolved promise for the provided value.
resolve("data"); },};Generator Methods
Section titled “Generator Methods”const const iterator: { values: () => Generator<1 | 2, void, unknown>;}
iterator = { values: () => Generator<1 | 2, void, unknown>
values: function* () { yield 1; yield 2; },};const const iterator: { values(): Generator<1 | 2, void, unknown>;}
iterator = { *function values(): Generator<1 | 2, void, unknown>
values() { yield 1; yield 2; },};Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your project targets environments that don’t support ES2015 shorthand syntax, this rule should be disabled.
Arrow functions used as property values that rely on lexical this, arguments, super, or new.target bindings are not flagged by this rule, as converting them to method shorthand would change their behavior.
Some codebases prefer explicit property assignments for consistency or clarity, particularly when mixing shorthand and longform syntax in the same object literal.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useConsistentObjectDefinitions - ESLint:
object-shorthand