For instance:
enum App {
App1 = "my-app1",
App2 = "my-app2",
}
const AppPaths: {
[ App.App1 ]: string;
[ App.App2 ]: string;
} = {
[ App.App1 ]: "/some/path/to/app1",
[ App.App2 ]: "/some/path/to/app2",
};
This approach is functional, but quite lengthy. I aim to streamline AppPaths
so it resembles the following:
const AppPaths: { [ key: keyof App ]: string } = ...
This results in an error:
An index signature parameter type cannot be a literal type or generic type. It might be helpful to utilize a mapped object type instead.
Consequently, I attempted using a mapped object type:
const AppPaths: { [ key in keyof App ]: string } = ...
// or
const AppPaths: { [ key in keyof typeof App ]: string } = ...
Both attempts yield the following error:
Object literal may only specify known properties, and '[ App.App1 ]' does not exist in type '{ readonly [x: number]: string; toString: string; charAt: string; charCodeAt: string; concat: string; indexOf: string; lastIndexOf: string; localeCompare: string; match: string; replace: string; search: string; ... 39 more ...; [Symbol.iterator]: string; }
Can the type declaration of this object be simplified?