3 ms·
On the one hand, yes, the code examples in that PR thread are kind of terrifying. On the other, the ability to map mechanically between type names would be rea
by gmac 6y ago
On the one hand, yes, the code examples in that PR thread are kind of terrifying.
On the other, the ability to map mechanically between type names would be really useful, and is something I’ve previously wished for. It would, for example, enormously simplify type generation for Zapatos[1], which currently creates multiple long object mappings for this purpose, such as:
export type SelectableForTable<T extends Table> = {
accounts: accounts.Selectable;
appleTransactions: appleTransactions.Selectable;
authors: authors.Selectable;
books: books.Selectable;
emailAuthentication: emailAuthentication.Selectable;
employees: employees.Selectable;
identityTest: identityTest.Selectable;
stores: stores.Selectable;
tags: tags.Selectable;
tableInOtherSchema: tableInOtherSchema.Selectable;
}[T];
[1] https://jawj.github.io/zapatos/ https://jawj.github.io/zapatos/
- Kinrany 6y agoSince you're generating types anyway, can't this be simplified to `tableTypes[T]['Selectable']`?
- gmac 6y agoNice thought, thanks, but I don't think so. The way things are set up, your `tableTypes[T]` would need to map table names to namespaces, and this gives errors like "Cannot use namespace 'X' as a type". Would be pleased to be proved wrong, though. :)