Skip to content

tsc compilation fails with TS 5.0.4+ and core@5.3.0 #8616

Description

@Thinkscape

Steps

  1. TS 5.0.4 or newer (tested on 5.0.4 and 5.1.3)
  2. Upgrade @keystone/core to 5.3.0
  3. Upgrade and lock down prisma and @prisma/client to 4.14.1
  4. Simplest list possible:
export const lists: Lists = {
  Order: list({
    access: {
      operation: {
        ...allOperations(({}) => true),
      },
    },
    fields: {
      foo: text(),
    },
  }),

Expected

Keystone dev starts.
tsc compiles successfully.

Actual

keystone dev works fine, admin functions. The app works.

tsc fails to compile due to type error.

(don't mind the redacted parts, just list names from real world app)

# tsc
src/keystone/lists/index.ts:25:7 - error TS2322: Type '{ query: (args: BaseAccessArgs<BaseListTypeInfo> & { operation: AccessOperation; }) => boolean; create: (args: BaseAccessArgs<BaseListTypeInfo> & { ...; }) => boolean; update: (args: BaseAccessArgs<...> & { ...; }) => boolean; delete: (args: BaseAccessArgs<...> & { ...; }) => boolean; }' is not assignable to type 'ListOperationAccessControl<AccessOperation, TypeInfo<any>> | { query: ListOperationAccessControl<"query", TypeInfo<any>>; create: ListOperationAccessControl<...>; update: ListOperationAccessControl<...>; delete: ListOperationAccessControl<...>; }'.
  Type '{ query: (args: BaseAccessArgs<BaseListTypeInfo> & { operation: AccessOperation; }) => boolean; create: (args: BaseAccessArgs<BaseListTypeInfo> & { ...; }) => boolean; update: (args: BaseAccessArgs<...> & { ...; }) => boolean; delete: (args: BaseAccessArgs<...> & { ...; }) => boolean; }' is not assignable to type '{ query: ListOperationAccessControl<"query", TypeInfo<any>>; create: ListOperationAccessControl<"create", TypeInfo<any>>; update: ListOperationAccessControl<...>; delete: ListOperationAccessControl<...>; }'.
    Types of property 'query' are incompatible.
      Type '(args: BaseAccessArgs<BaseListTypeInfo> & { operation: AccessOperation; }) => boolean' is not assignable to type 'ListOperationAccessControl<"query", TypeInfo<any>>'.
        Types of parameters 'args' and 'args' are incompatible.
          Type 'BaseAccessArgs<TypeInfo<any>> & { operation: "query"; }' is not assignable to type 'BaseAccessArgs<BaseListTypeInfo> & { operation: AccessOperation; }'.
            Type 'BaseAccessArgs<TypeInfo<any>> & { operation: "query"; }' is not assignable to type 'BaseAccessArgs<BaseListTypeInfo>'.
              The types of 'context.sessionStrategy' are incompatible between these types.
                Type 'SessionStrategy<any, __TypeInfo<any>> | undefined' is not assignable to type 'SessionStrategy<any, BaseKeystoneTypeInfo> | undefined'.
                  Type 'SessionStrategy<any, __TypeInfo<any>>' is not assignable to type 'SessionStrategy<any, BaseKeystoneTypeInfo>'.
                    Types of property 'get' are incompatible.
                      Type '(args: { context: KeystoneContext<__TypeInfo<any>>; }) => Promise<any>' is not assignable to type '(args: { context: KeystoneContext<BaseKeystoneTypeInfo>; }) => Promise<any>'.
                        Types of parameters 'args' and 'args' are incompatible.
                          Type '{ context: KeystoneContext<BaseKeystoneTypeInfo>; }' is not assignable to type '{ context: KeystoneContext<__TypeInfo<any>>; }'.
                            The types of 'context.db' are incompatible between these types.
                              Type 'KeystoneDbAPI<Record<string, BaseListTypeInfo>>' is missing the following properties from type 'KeystoneDbAPI<{ readonly Order: TypeInfo<any>; readonly REDACTED: TypeInfo<any>; readonly OrderItem: TypeInfo<any>; readonly Payment: TypeInfo<any>; ... 10 more ...; readonly REDACTED: TypeInfo<...>; }>': Order, REDACTED, OrderItem, Payment, and 11 more.

image

tsconfig.json

{
  "compilerOptions": {
    "target": "es2017",
    "lib": ["dom", "dom.iterable", "ES2023", "ESNext"],
    "allowJs": true,
    "checkJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "noUncheckedIndexedAccess": true,
    "baseUrl": ".",
    "paths": {
      "roev/*": ["./src/*"],
      "@public/*": ["/public/*"]
    },
    "plugins": [
      {
        "name": "next"
      }
    ],
    "noEmit": false,
    "outDir": "dist/"
  },
  "include": [
    ".eslintrc.cjs",
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.cjs",
    "**/*.mjs",
    ".next/types/**/*.ts"
  ],
  "exclude": ["node_modules"]
}

Workaround:

  • I've nuked and reinstalled everything to be sure.
  • I've made sure prisma client is generated correctly after upgrades.
  • Running keystone dev and letting it generate does not fix the issue
  • It worked fine with @keystone/core@5.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions