Here's an example of an issue with a predictable outcome:
const actionTypes = {
name: {
set: "name/set",
},
} as const;
type ActionTypes = { [key: string]: (string | ActionTypes) }; //record value is string or ActionTypes
// "GetActionType" circularly references itself
type GetActionType<A extends ActionTypes> = A extends Record<
string,
infer Value
>
? Value extends string
? Value
: GetActionType<Value> // "GetActionType" is not generic
: unknown;
type SiteAction = GetActionType<typeof actionTypes>; // "GetActionType" is not generic
// expected to be 'name/set'
Is it possible to avoid errors in this scenario?
Edit
Adds as const
to declaration of actionTypes and correctly references the constant below
TypeScript version 4.0.2
Playground link.