I am using ts and keep getting stuck when trying to create const that can be used by just changing a simple element.keep getting A class member cannot have the 'const' keyword
code:
const LINKS = {
Summary: 82,
Telephone: 83
};
itemLocator(ItemId): Locator {
const navItemSelector = `'div[id="${ItemId}"]'`
return page.locator(itemLocator)
}
tired doing const function, and const
The duplicate answers that suggest using readonly in the comments are valid for simple properties.
In your case, because you're using an object property, you need an additional const assertion:
class Test {
readonly LINKS = {
Summary: 82,
Telephone: 83
} as const;
}
const test = new Test();
test.LINKS = {}; // error
test.LINKS.Summary = 83; // error
Without the const assertion, you would still be able to change the value Summary and Telephone values inside LINKS.