Skip to content

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 and stylisticStrict 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.

const name = "Alice";
const user = { name: name };
const value = 42;
const settings = { value: value, other: true };
const config = {
handler: function () {
return "result";
},
};
const service = {
load: async function () {
return await Promise.resolve("data");
},
};
const iterator = {
values: function* () {
yield 1;
yield 2;
},
};

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.