sqltyper
sqltyper copied to clipboard
Type errors when using with Postgres.js
Tried to use with Postgres.js
TypeScript error:
const result: postgres.RowList<postgres.Row[]>
Type 'RowList<Row[]>' is not assignable to type '{ name: string; }[]'.
The types returned by 'pop()' are incompatible between these types.
Type 'Row | undefined' is not assignable to type '{ name: string; } | undefined'.
Property 'name' is missing in type 'Row' but required in type '{ name: string; }'.ts(2322)
Query:
SELECT
name
FROM projects
WHERE id = ${projectID}
Generated code:
// Generated by sqltyper from get_project.sql.
// Do not edit directly. Instead, edit get_project.sql and re-run sqltyper.
import * as postgres from 'postgres'
export async function getProject(
sql: postgres.Sql<{}>,
params: { projectID: number }
): Promise<Array<{ name: string }>> {
const result = await sql.unsafe(
`SELECT
name
FROM projects
WHERE id = $1
`,
[params.projectID]
)
return result
}
Which version of postgres.js are you using? sqltyper uses it internally too, but it might not be exactly the latest version, because it had to be patched a bit.