Skip to content

How to pass Sql object to a function in TypeScript? #384

Answered by Minigugus
ariofrio asked this question in Q&A
Discussion options

You must be logged in to vote

TTypes is intended to pass custom types information to the sql tagged template string, in order to provide rich completion for parameters (e.g. sql`SELECT ${1n}`; only works if the postgres.BigInt custom type is passed to the postgres() function; the same apply to any user-defined custom types). Without TTypes, it wouldn't be possible to validate parameters correctly (using any everywhere), and thus not possible neither to validate different helpers formats (because of conflicting function signatures), resulting in a type definition like type Sql = (...args: any) => any, which is quite useless...

TTypes just map custom types names to the value they accept/provide, so in your case, you cas…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ariofrio
Comment options

Answer selected by ariofrio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants