import { knex, Knex } from '../types'; import { clientConfig } from './common'; import { expectType } from 'tsd'; const knexInstance = knex(clientConfig); interface User { id: number; age: number; name: string; active: boolean; departmentId: number; } interface Department { id: number; departmentName: string; } interface Article { id: number; subject: string; body?: string; authorId?: string; } interface Ticket { name: string; from: string; to: string; at: Date; } declare module '../types/tables' { interface Tables { users_inferred: User; departments_inferred: Department; articles_inferred: Article; users_composite: Knex.CompositeTableType< User, { insert: 'insert' }, { update: 'update' } >; departments_composite: Knex.CompositeTableType< Department, { insert: 'insert' }, { update: 'update' } >; articles_composite: Knex.CompositeTableType< Article, { insert: 'insert' }, { update: 'update' } >; } } const main = async () => { // # Select: expectType(await knexInstance('users')); // This test (others similar to it) may seem useless but they are needed // to test for left-to-right inference issues eg: #3260 expectType(await knexInstance('users')); expectType(await knexInstance('users')); expectType(await knexInstance('users_inferred')); expectType(await knexInstance('users_composite')); expectType(await knexInstance('users').select('id')); expectType[]>(await knexInstance('users').select('id')); expectType[]>(await knexInstance('users_inferred').select('id')); expectType[]>(await knexInstance('users_composite').select('id')); expectType[]>( await knexInstance('users_inferred').select('id').select('age') ); expectType[]>( await knexInstance('users_composite').select('id').select('age') ); expectType[]>( await knexInstance('users_inferred').select('id', 'age') ); expectType[]>( await knexInstance('users_composite').select('id', 'age') ); expectType | undefined>( await knexInstance.first('id').from('users_inferred') ); expectType | undefined>( await knexInstance.first('id').from('users_composite') ); };