Skip to content

select with refs no longer infers fields after typescript 3.8 #3932

@Naddiseo

Description

@Naddiseo

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

  1. Explain what kind of behaviour you are getting and how you think it should do
    When using select([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

  2. Error message

  • None, typescript propblem
  1. 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

  1. Explain what is your use case
  • Using the same way as the docs suggest, but breaks as of TS3.8
  1. Explain what kind of feature would support this

  2. 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?

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