Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type errors when using with Postgres.js #176

Open
maxpain opened this issue Jun 9, 2021 · 1 comment
Open

Type errors when using with Postgres.js #176

maxpain opened this issue Jun 9, 2021 · 1 comment

Comments

@maxpain
Copy link

maxpain commented Jun 9, 2021

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
}
@akheron
Copy link
Owner

akheron commented Jun 9, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants