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 ts stylistic presets.
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 name = "Alice";const user = { name: name };const value = 42;const settings = { value: value, other: true };const name = "Alice";const user = { name };const value = 42;const settings = { value, other: true };Method Shorthand
Section titled “Method Shorthand”const config = { handler: function () { return "result"; },};const service = { load: async function () { return await Promise.resolve("data"); },};const config = { handler() { return "result"; },};const service = { async load() { return await Promise.resolve("data"); },};Generator Methods
Section titled “Generator Methods”const iterator = { values: function* () { yield 1; yield 2; },};const iterator = { *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