I had a type, defined as such in a definition file (.d.ts
) (also, the code is shortened):
type myType = {
[key: string]: any;
myKeyOne: string;
myKeyTwo: number;
};
which was working fine, but for the needs of my project, I need to make these keys a little bit more dynamic since they are prone to change a lot.
So I declared some constants in a constants.ts
file:
export const MY_KEY_ONE = 'myKeyOne';
export const MY_KEY_TWO = 'myKeyTwo';
and used them as such in the previous file:
type myType = {
[key: string]: any;
[MY_KEY_ONE]: string;
[MY_KEY_TWO]: number;
};
But it broke all my code, stating that it
Cannot find name 'myType'
Am I not allowed to do that? Is there any way to achieve this?