Skip to content

TypeScript issues with dynamic inserts #674

@noah-lee

Description

@noah-lee

I am getting what appears to be inconsistent TypeScript errors when writing dynamic insert queries:

Issue

// No errors:
const users = await sql<UserDto[]>`INSERT INTO users ${sql(payload)} returning *`;
// or
const helper = sql(payload, "username", "email", "password");
const users = await sql<UserDto[]>`INSERT INTO users ${helper} returning *`;

// Error: Type of operand must either be a valid promise or must not contain a callable then member.
const users = await sql<UserDto[]>`INSERT INTO users ${sql(payload, "username", "email", "password")} returning *`;

Expected
I would expect all three above to be valid but the last one throws a TypeScript error.

Is this the intended behavior?

tsconfig

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ES2022",
    "strict": true,
    "sourceMap": true,
    "outDir": "dist",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions