#Why this generics infer this intersection of types?

14 messages · Page 1 of 1 (latest)

past prairie
#

Hey guys, I'm doing maintenance on the query builder, and I'm trying to modify it so that you don't have to pass generics to the function and the builder can infer types from the table passed at the beginning. To improve DX from my team.

The query builder is functional, but with my modifications if i no pass generics, my select method allow only the intersection from database that is passed in .database() method.

What I am missing to make everything more dynamic here? The method allow only intersection has to do with depth of object (DataBase type)?

Here i playground to testing my code https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgKoGdrIN4ChnLAAmAXMiAK4C2ARtANz7lxURnphSgDmjBEVOMAA27Tjz7IADnHToA7gHsopZBy4heTBFAhxIRAPr6yAEX0RJFKUQtGTyc5EYBfXLlCRYiFAAUoikQUCGA4TMRklLQMTCAsbGrimpJEEOg6wFJgwIogYhpaBFJcSJHUdFCSOnoGxmBmFq7untDwSMgA8ipYeAQR5OUxBBSYUIb9URWSxYHBYOOqk0PIAI4UcODAYACeZdGV2rp2dQ3OuG64O1IoTnAAQrIQAKIAHixSwigAvGHDo2QYZYzIIhMj+WYhSTKVJQMhdGFNXCpBDCOC6ZisdAydoARQo0G2dwoIhhv2QMAoIBCORAyFsYDgNEeAB4mARTHcADTINnIAAqjM+yAgL0gICI6GQAGsINtFDBHHdkD8ZXKFRzOUwAHwACiINDMdwAlGQ8QSiSToABZCBgAAWgXQzI1-MFEC1jCYVxQZqghOJwhhNvtjtZBHZXN5ApoQpFYol0tl8sVmoIWuVZIIMACVDIOoZMYS0c+RuV6d9-stUGDDolzq5rsLWtT4cwn1ByB16DIquTHIA2sWIABdUtfcv4v0WwPW221p0uofN3k0AOqHVj9PgqjATDMgBuimIy4IbguuAQuQ4yCo21MNAAkiAOBt2j9sC5kLJHPp7o9Xu8nyejqsjbFSnabmSAD0UHIAAyhA7ahKwIZEF+wjCIo8jILkwjbIQ4DQJg1K5MgdBgPIEAQLStwPJgAFUB8KDeugTBwPIQihBW04wgAdPSjKPDqt73k+L5UhARq8rx2aKFQOoAEQjNAClSeGyC8W2EAhIpqnSauJIbpIMHwYh2nIXOgToZh2FwBhyAseSObIMpUAOW6bEcVsyDcWu0D8b+TJ7rR-5vIxnzckpowKbqImPs+DISWp4YyTmimuXp6maWZOkKZlKUGYGRnnEaG64EAA

austere harborBOT
#

@past prairie Here's a shortened URL of your playground link! You can remove the full link from your message.

luisao#9526

Preview:```ts
interface User {
id: number
name: string
email: string
password: string
created_at: Date
updated_at: Date
}

interface Product {
id: number
name: string
description: string
price: number
created_at: Date
}

interface Or
...```

viral sigil
#
from: <T extends Table>(table: T) => QueryBuilderMethods<DB, T>
viral sigil
#

You want it to specialize to a specific table, not just any table.

past prairie
#

it does not extend the same table?

#

or it extends the same type?

#

i think this make sense

viral sigil
#

It's basically:

type Color = 'red' | 'green' | 'blue'

declare function notSpecialized(color: Color): Color
const result1 = notSpecialized('red')

declare function specialized<T extends Color>(color: T): T
const result2 = specialized('red')
#

!ts result1 result2

austere harborBOT
#
const result1: Color /* 4:7 */``````ts
const result2: "red" /* 7:7 */```
past prairie
#

nice

#

i think i understand

#

thanks for example and explanation