Skip to content

Commit 396d5dc

Browse files
committed
fix(typegen): table return type
1 parent 894b14c commit 396d5dc

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/server/templates/typescript.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,25 @@ export interface Database {
225225
({ name, type }) => `${JSON.stringify(name)}: ${type}`
226226
)} }`
227227
})()}
228-
Returns: ${pgTypeToTsType(return_type, types, schemas)}
228+
Returns: ${(() => {
229+
const tableArgs = args.filter(({ mode }) => mode === 'table')
230+
231+
if (tableArgs.length > 0) {
232+
const argsNameAndType = tableArgs.map(({ name, type_id }) => {
233+
const type = types.find(({ id }) => id === type_id)
234+
if (!type) {
235+
return { name, type: 'unknown' }
236+
}
237+
return { name, type: pgTypeToTsType(type.name, types, schemas) }
238+
})
239+
240+
return `{ ${argsNameAndType.map(
241+
({ name, type }) => `${JSON.stringify(name)}: ${type}`
242+
)} }[]`
243+
}
244+
245+
return pgTypeToTsType(return_type, types, schemas)
246+
})()}
229247
}`
230248
)
231249
.join('|')}`

0 commit comments

Comments
 (0)