I have a group of objects with const
values, and these objects should follow a specific type definition.
The problem is that when I assign a type on the object, no longer get autocomplete or type annotations for them.
type URLDefinition = {
[key: Uppercase<string>]: string;
};
const General: URLDefinition = {
BASE: "api/",
} as const;
const Search = {
ACCOUNTS: "api/v1/accounts",
lowerPath: "api/v1", // unable to enforce Uppercase strict
// typing, because lack of type definition
} as const;
console.log(General.WRONG); // won't throw error 👎
console.log(Search.WRONG); // throw error 👍
How can I have both an object type definition and autocomplete at the same time?