Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prisma list of enums TS bug #1255

Closed
SpeedySH opened this issue Jul 26, 2024 · 6 comments
Closed

prisma list of enums TS bug #1255

SpeedySH opened this issue Jul 26, 2024 · 6 comments

Comments

@SpeedySH
Copy link

Greetings, encountered a bug that does not affect operability but is a typing error.
The essence is as follows:
When trying to create a field that is an enum array, I get the following TS error:

Type ‘(t: InputFieldBuilder<ExtendDefaultTypes<SchemaBuilderTypes>, “InputObject”>) => { key: InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, string | ... 1 more ... | undefined>; value: InputFieldRef<...>; isSensitive: InputFieldRef<...>; environments: InputFieldRef<... >; }‘ cannot be assigned to the type “Partial<Record<keyof EnvironmentVariableCreateInput, unknown>> & (PrismaCreateFields<ExtendDefaultTypes<SchemaBuilderTypes>, { ...; }> | ((t: InputFieldBuilder<...>) => PrismaCreateFields<...>))”)’.
  Type ‘(t: InputFieldBuilder<ExtendDefaultTypes<SchemaBuilderTypes>, “InputObject”>) => { key: InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, string | ... 1 more ... | undefined>; value: InputFieldRef<...>; isSensitive: InputFieldRef<...>; environments: InputFieldRef<... >; }‘ cannot be assigned to the type “Partial<Record<keyof EnvironmentVariableCreateInput, unknown>> & ((t: InputFieldBuilder<ExtendDefaultTypes<SchemaBuilderTypes>, ”InputObject’>) => PrismaCreateFields<...>)’.
    Type ‘(t: InputFieldBuilder<ExtendDefaultTypes<SchemaBuilderTypes>, “InputObject”>) => { key: InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, string | ... 1 more ... | undefined>; value: InputFieldRef<...>; isSensitive: InputFieldRef<...>; environments: InputFieldRef<... >; }‘ cannot be assigned to type “(t: InputFieldBuilder<ExtendDefaultTypes<SchemaBuilderTypes>, ”InputObject’>) => PrismaCreateFields<ExtendDefaultTypes<SchemaBuilderTypes>, { ...; }>’.
      Call signature return value types ‘{ key: InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, string | null | undefined>; value: InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, string | ... 1 more ... | undefined>; isSensitive: InputFieldRef<...>; environments: InputFieldRef<...>; }‘ and “PrismaCreateFields<ExtendDefaultTypes<SchemaBuilderTypes>, { Name: ”EnvironmentVariable’; Shape: { id: number; key: string; value: string; isSensitive: boolean; projectId: number | null; teamId: number | null; environments: Environment[]; }; ... 9 more ...; Relations: { ...; }; }; }>’ are incompatible.
        The ‘environments’ types are incompatible between these types.
          The type ‘InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, ValuesFromEnum<{ DEVELOPMENT: “DEVELOPMENT”; PRODUCTION: “PRODUCTION”; PREVIEW: “PREVIEW”; }>[] | null | undefined>’ cannot be assigned to the type ‘NonListInputWithShape<ExtendDefaultTypes<SchemaBuilderTypes>, Environment[]> | undefined’.
            Type ‘InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, ValuesFromEnum<{ DEVELOPMENT: “DEVELOPMENT”; PRODUCTION: “PRODUCTION”; PREVIEW: ‘PREVIEW‘; }>[] | null | undefined>’ cannot be assigned to the type ‘InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, Environment | null | undefined> | InputRef<Environment>’.
              The type ‘InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, ValuesFromEnum<{ DEVELOPMENT: “DEVELOPMENT”; PRODUCTION: “PRODUCTION”; PREVIEW: “PREVIEW”; }>[] | null | undefined>’ cannot be assigned to the type ‘InputFieldRef<ExtendDefaultTypes<SchemaBuilderTypes>, Environment | null | undefined>’.
                The ‘$inferInput’ property types are incompatible.
                  The type ‘ValuesFromEnum<{ DEVELOPMENT: “DEVELOPMENT”; PRODUCTION: “PRODUCTION”; PREVIEW: “PREVIEW”; }>[] | null | undefined’ cannot be assigned to the type ‘Environment | null | undefined’.ts(2322)
types.d.ts(84, 5): The expected type comes from the ‘fields’ property declared here in the type ‘PrismaCreateOptions<ExtendDefaultTypes<SchemaBuilderTypes>, { Name: “EnvironmentVariable”; Shape: { id: number; key: string; value: string; isSensitive: boolean; projectId: number | null; teamId: number | null; environments: Environment[]; }; ... 9 more ...; Relations: { ...; }; }; }, Partial<...>>’

At the same time, the performance is not affected in any way. Also below is the full code

import {  Environment,} from "@prisma/client"; // it is native enum

const EnvironmentEnum = builder.enumType(Environment, { name: "Environment" });

const EnvironmentVariableCreateInput = builder.prismaCreate("EnvironmentVariable", {
  name: "EnvironmentVariableCreateInput",
  fields: (t) => ({
    key: t.string(),
    value: t.string(),
    isSensitive: t.boolean(),
    environments: t.field({ type: t.listRef(EnvironmentEnum) }),
  }),
});
@SpeedySH SpeedySH changed the title prismaCreate list of enums TS bug prisma list of enums TS bug Jul 26, 2024
@hayes
Copy link
Owner

hayes commented Jul 26, 2024

Thanks for the report, I'll try to get this fixed in the next day or so.

In the mean time, this should also work:

import {  Environment,} from "@prisma/client"; // it is native enum

const EnvironmentEnum = builder.enumType(Environment, { name: "Environment" });

const EnvironmentVariableCreateInput = builder.prismaCreate("EnvironmentVariable", {
  name: "EnvironmentVariableCreateInput",
  fields: (t) => ({
    key: t.string(),
    value: t.string(),
    isSensitive: t.boolean(),
    environments: t.field({ type: [EnvironmentEnum] }),
  }),
});

@SpeedySH
Copy link
Author

Thanks for the report, I'll try to get this fixed in the next day or so.

In the mean time, this should also work:

import {  Environment,} from "@prisma/client"; // it is native enum

const EnvironmentEnum = builder.enumType(Environment, { name: "Environment" });

const EnvironmentVariableCreateInput = builder.prismaCreate("EnvironmentVariable", {
  name: "EnvironmentVariableCreateInput",
  fields: (t) => ({
    key: t.string(),
    value: t.string(),
    isSensitive: t.boolean(),
    environments: t.field({ type: [EnvironmentEnum] }),
  }),
});

I tried to do the same, following the examples in the documentation. Exactly the same TS error :(

Thanks, waiting for a fix, will put @ts-ignore up in the meantime

@hayes
Copy link
Owner

hayes commented Jul 26, 2024

I think I misunderstood the issue, it looks like it's expecting a single Environment rather than a list, I'll try to figure out what's going on with that

@SpeedySH
Copy link
Author

I think I misunderstood the issue, it looks like it's expecting a single Environment rather than a list, I'll try to figure out what's going on with that

The dilemma here is that I have tried all the ways to declare the list as a field where only enum values are expected. None of them allows to do it without an error, at the current stage.

Thanks anyway

@hayes
Copy link
Owner

hayes commented Jul 26, 2024

I think the issue is in the Prisma utils plugin, I think it just doesn't handle array columns, but that shouldn't be too hard to fix

@hayes
Copy link
Owner

hayes commented Jul 26, 2024

should be fixed in the latest release

@hayes hayes closed this as completed Jul 26, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants