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

@paramvalue A promise.

@returnsA promise whose internal state matches the provided promise.

resolve
("data");
},
};
const
const iterator: {
values: () => Generator<1 | 2, void, unknown>;
}
iterator
= {
values: () => Generator<1 | 2, void, unknown>
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 ❤️‍🔥 around the world by the Flint team and contributors.