My data setup is as follows (I am not declaring it as an enum
because it is used in both TypeScript server code and non-TypeScript client code):
import { enumType } from 'nexus';
export const TYPE_ENUM = Object.freeze({
H: 'H',
S: 'S',
});
export const TYPES = Object.freeze(Object.values(TYPE_ENUM));
export const MyType = enumType({
name: 'MyType',
members: TYPES,
});
While working on this, TypeScript raised the following warning related to the members
field:
Type '(readonly string[])[]' is not assignable to type '(string | EnumMemberInfo)[] | Record<string, string | number | boolean | object>'.
Type '(readonly string[])[]' is not assignable to type '(string | EnumMemberInfo)[]'.
Type 'readonly string[]' is not assignable to type 'string | EnumMemberInfo'.
Type 'readonly string[]' is not assignable to type 'string'.ts(2322)
enumType.d.ts(29, 3): The expected type comes from property 'members' which is declared here on type 'EnumTypeConfig<"MyType">'
I understand the issue. It's not possible to insert a readonly string[]
into something that expects a string[]
due to their differences. My inquiry is about the best approach to resolve this.
I have noted that unwrapping and recreating the array seems to work: members: [...TYPES]
, but it doesn't feel quite right.