I have an object like this:
{
element: 'tool-app',
file: '/tool-app.js',
icon: 'csr-icon',
name: 'Planning view',
id: 'planning-view'
}
I want to store the value of icon in a variable and use it instead. First I define a constant:
const icon = 'csr-icon';
I then try to use the above icon to the object:
{
element: 'tool-app',
file: '/tool-app.js',
icon: icon, ///change here
name: 'Planning view',
id: 'planning-view'
}
It should be equal, but Tslint returns an error:
Expected property shorthand in object literal ('{icon}'). (object-literal-shorthand)tslint(1)
How come?
I have an object like this:
{
element: 'tool-app',
file: '/tool-app.js',
icon: 'csr-icon',
name: 'Planning view',
id: 'planning-view'
}
I want to store the value of icon in a variable and use it instead. First I define a constant:
const icon = 'csr-icon';
I then try to use the above icon to the object:
{
element: 'tool-app',
file: '/tool-app.js',
icon: icon, ///change here
name: 'Planning view',
id: 'planning-view'
}
It should be equal, but Tslint returns an error:
Expected property shorthand in object literal ('{icon}'). (object-literal-shorthand)tslint(1)
How come?
Share Improve this question asked Mar 22, 2021 at 9:33 SharePointBeginnerSharePointBeginner 3591 gold badge3 silver badges11 bronze badges1 Answer
Reset to default 22This error tells you that instead of icon: icon,
, you can write only icon
because the property name is the same as your const.
So your new object should look like this :
{
element: 'tool-app',
file: '/tool-app.js',
icon,
name: 'Planning view',
id: 'planning-view'
}
This is called "shorthand" :)