diff --git a/packages/typegen/test/index.test.ts b/packages/typegen/test/index.test.ts index e1e1fdd9..dcb0cc26 100644 --- a/packages/typegen/test/index.test.ts +++ b/packages/typegen/test/index.test.ts @@ -6,11 +6,31 @@ import {join} from 'path' import {tmpdir} from 'os' import {expectTypeOf} from 'expect-type' +type Brands = { + CountInfo: { + a_count: 'count' + } +} + +type Branded = TypeName extends keyof Brands + ? Field extends keyof Brands[TypeName] + ? T & {_brand: Brands[TypeName][Field]} + : T + : T + +type OrigKnownTypes = typeof knownTypes + +type WrappedKnownTypes = { + [TypeName in keyof OrigKnownTypes]: { + [Field in keyof OrigKnownTypes[TypeName]]: Branded + } +} + describe('type generator', () => { const writeTypes = join(__dirname, 'generated/main') const {sql, poolConfig} = setupTypeGen({ reset: true, - knownTypes, + knownTypes: knownTypes as WrappedKnownTypes, writeTypes, }) const connectionString = `postgresql://postgres:postgres@localhost:5433/postgres` @@ -47,11 +67,14 @@ describe('type generator', () => { await slonik.query(sql.Foo`select * from foo`) // make sure duplicate doesn't create two types. const countInfo = await slonik.one(sql.CountInfo` - select count(*) as a_count, a as a_value - from foo - group by a - `) - expectTypeOf(countInfo).toEqualTypeOf<{a_count: number; a_value: string}>() + select count(*) as a_count, a as a_value + from foo + group by a +`) + expectTypeOf(countInfo).toEqualTypeOf<{ + a_count: number & {_brand: 'count'} + a_value: string + }>() const generatedFiles = readdirSync(writeTypes) generatedFiles.forEach(f => {