kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.22k stars 259 forks source link

Typings broken with typescript 5.4.4: Type 'TB | ExtractTableAlias<DB, TE>' does not satisfy the constraint 'keyof DB' #898

Closed rvion closed 6 months ago

rvion commented 6 months ago

When bumping typescript 5.3.3 => 5.4.2

node_modules/kysely/dist/cjs/expression/expression-builder.d.ts:196:80 - error TS2344: Type 'TB | ExtractTableAlias<DB, TE>' does not satisfy the constraint 'keyof DB'.
  Type 'ExtractTableAlias<DB, TE>' is not assignable to type 'keyof DB'.
    Type 'ExtractTableAlias<DB, keyof DB & string>' is not assignable to type 'keyof DB'.

196     selectFrom<TE extends keyof DB & string>(from: TE): SelectQueryBuilder<DB, TB | ExtractTableAlias<DB, TE>, {}>;
                                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/kysely/dist/cjs/query-creator.d.ts:125:82 - error TS2344: Type 'ExtractTableAlias<DB, TE>' does not satisfy the constraint 'keyof DB'.
  Type 'ExtractTableAlias<DB, keyof DB & string>' is not assignable to type 'keyof DB'.
    Type 'string | (string extends keyof DB ? keyof DB & string : never)' is not assignable to type 'keyof DB'.
      Type 'string' is not assignable to type 'keyof DB'.

125     selectFrom<TE extends keyof DB & string>(from: TE[]): SelectQueryBuilder<DB, ExtractTableAlias<DB, TE>, {}>;
                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~
koskimas commented 6 months ago

There was a clear error in ExtractTableAlias that the new typescript version caught. That was easily fixed once I was able to decrypt the error messages 😓.

The remaining issue is with the From and FromTables types that seem to be all kinds of broken.

koskimas commented 6 months ago

Phew! I think I got it. Still testing the typing performance impact of my changes.

koskimas commented 6 months ago

I'll release a new patch version today.

koskimas commented 6 months ago

0.27.3 is now released. Let me know if you have further issues with that one.