-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Environment
Knex version: 0.19.5 / 0.21.2
Database + version: postgresql 11
OS: Ubuntu 20.04
Select applicable template from below.
If issue is about oracledb support, tag @ atiertant. For MSSql tag @ smorey2.
Rest of dialects don't need tags.
If issue is about TypeScript definitions, tag @lorefnon.
Bug
-
Explain what kind of behaviour you are getting and how you think it should do
When usingselect([knex.ref('id'), knex.ref('field')])
the return type no longer contains all fields starting with typescript 3.8, and will only contain a single field -
Error message
- None, typescript propblem
- Reduced test code, for example in https://npm.runkit.com/knex or if it needs real
database connection to MySQL or PostgreSQL, then single file example which initializes
needed data and demonstrates the problem.
import Knex from 'knex';
interface Table {
id: string
field_a: string
}
const knex = Knex({ client: 'pg', connection: 'postgresql://user:pass@db:5432/db' });
const KTable = knex<Table>('table');
// expected type = `{ "id": string, "field_a": string };
/*
starting with typescript 3.8, the actual return type can be `{"id": string}` or `{"field_a": string}` depending on how it gets passed to `select()`
*/
const result = await KTable.select([knef.ref('id'), knef.ref('field_a')]);
Feature discussion / request
- Explain what is your use case
- Using the same way as the docs suggest, but breaks as of TS3.8
-
Explain what kind of feature would support this
-
Give some API proposal, how the feature should work
I'm not sure if this is a TS bug, or a knex bug, but since it works in multiple versions of knex, but stopped working in TS3.8, I'm thinking it could be that TS changed something. I had a look at the typings, and it could be that the UnionToIntersection
utility is no longer working in TS3.8 and would need updating?