I have a specific goal in mind:
// first.ts
export enum First {
One,
Two,
Three
}
// second.ts
export enum Second {
One,
Two,
Three
}
// factory.ts
// For those unfamiliar, Record represents an object with key value pairs
type NotWorkingType<T> = Record<T , string>;
// I'm struggling to make either of these objects function properly.
// An important note is that external enums like First and Second can be extended by adding a "Third" without any issues.
const testObject: NotWorkingType<First> = {
[First.One]: 'first',
[First.Two]: 'second',
[First.Three]: 'third',
}
const testObject: NotWorkingType<Second> = {
[First.One]: 'first',
[First.Two]: 'second',
[First.Three]: 'third',
}
The current issue arises here:
// Type 'T' does not satisfy the constraint 'string | number | symbol'.
// Type 'T' is not assignable to type 'symbol'.(2344)
// |
// v
type NotWorkingType<T> = Record<T , string>;
I attempted to utilize k in keyof typeof T
like this as well:
type NotWorkingOtherType<T> = {
// 'T' only refers to a type, but is being used as a value here.(2693)
// |
// v
[k in keyof typeof T]: string;
}
No matter how I try to use generic parameters, it seems enums just won't cooperate.
Is there something crucial that I am overlooking?