You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript boolean types in template string interpolation are not correctly inferred as boolean, but instead as boolean | null
To Reproduce
Steps to reproduce the behavior:
// 💥 Query has incorrect type annotation.// Expected: { has_private_url: boolean; }// Actual: { has_private_url: boolean | null; }[]awaitsql<{has_private_url: boolean}[]>` SELECT${trueasboolean} AS has_private_url FROM users`;
Also same problem with no TS type assertion:
// 💥 Query has incorrect type annotation.// Expected: { has_private_url: boolean; }// Actual: { has_private_url: boolean | null; }[]awaitsql<{has_private_url: boolean}[]>` SELECT${true} AS has_private_url FROM users`;
Expected behavior
Inference as boolean
Screenshots
--
Desktop (please complete the following information):
OS: macOS Sequoia 15.0 (24A335)
PostgreSQL version 14
Version 3.4.4
Additional context
I was thinking that this may relate to the isColumnNonNullable() function, but since I cannot see anything in the AST related to interpolated values (also not sure what keywords to search for), I'm thinking that maybe the interpolation happens at an earlier step, before the parsing, eg somewhere related to this code:
Describe the bug
TypeScript boolean types in template string interpolation are not correctly inferred as
boolean
, but instead asboolean | null
To Reproduce
Steps to reproduce the behavior:
Also same problem with no TS type assertion:
Expected behavior
Inference as
boolean
Screenshots
--
Desktop (please complete the following information):
Additional context
I was thinking that this may relate to the
isColumnNonNullable()
function, but since I cannot see anything in the AST related to interpolated values (also not sure what keywords to search for), I'm thinking that maybe the interpolation happens at an earlier step, before the parsing, eg somewhere related to this code:safeql/packages/eslint-plugin/src/utils/ts-pg.utils.ts
Lines 61 to 98 in 86f5cd6
With a few hints as to how the system works, I would love to open a PR fixing this.
The text was updated successfully, but these errors were encountered: