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

TypeScript issues with dynamic inserts #674

Closed
noah-lee opened this issue Sep 11, 2023 · 1 comment · Fixed by #679
Closed

TypeScript issues with dynamic inserts #674

noah-lee opened this issue Sep 11, 2023 · 1 comment · Fixed by #679

Comments

@noah-lee
Copy link

noah-lee commented Sep 11, 2023

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
  },
}
@alpharder
Copy link
Contributor

This shouldn't be an intended behavior, I've prepared a fix at #679

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

Successfully merging a pull request may close this issue.

3 participants