keystonejs / keystonejs/keystone

`db.idField` settings are not reflected in generated types

Open
#8,846 2 comments 0 reactions 1 assignee Claimed by @dcousens View on GitHub
Dominant language
TypeScript
Stars
10k
Forks
1.3k
Avg merge
19h 14m
Merged PRs (30d)
19

Description

To reproduce, create the following schema:
```ts
export const lists: Lists = {
testfield: list({
access: allowAll,
db: {
idField: {
kind: 'autoincrement',
type: 'Int',
},
},
fields: {},
}),
singleton: list({
access: allowAll,
isSingleton: true,
fields: {},
}),
}
```

This should result in the `.keystone/types.ts` file containing a type called `testfieldWhereUniqueInput`.

It does, but the type of the id field is incorrect:

```ts
export type testfieldWhereUniqueInput = {
readonly id?: Scalars['ID'] | null;
};
```

`Scalars['ID']` is a string, but the id should be a number. I would expect it to be `Scalars['Int']` instead.

This also happens for singletons, because `isSingleton: true` forces `db.idField.type` to be `Int`.

It's not super noticeable normally, but if you start using the generated types in your schema, you'll notice that there is a red squiggly on all your list definitions. The error you get will usually contain the string `The types of 'context.db' are incompatible between these types.`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.