Skip to content

Type errors when using with Postgres.js #176

Open
@maxpain

Description

@maxpain

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions