-
-
Notifications
You must be signed in to change notification settings - Fork 105
Open
Labels
Description
Postgres qualifies array of nullable strings to be typeof text[]
But pgtyped generates (string)[]
, see:
.
.
.
example.sql
/* @name example */
SELECT pg_typeof(:input!::text[]);
Generates to:
example.queries.ts
/** Types generated for queries found in "src/report/upload/queries/example.queries.sql" */
import { PreparedQuery } from '@pgtyped/runtime';
export type stringArray = (string)[];
/** 'Example' parameters type */
export interface IExampleParams {
input: stringArray; // 👈 Type discrepancy, PG supports NULL as an element too.
}
/** 'Example' return type */
export interface IExampleResult {
pg_typeof: unknown | null;
}
/** 'Example' query type */
export interface IExampleQuery {
params: IExampleParams;
result: IExampleResult;
}
const exampleIR: any = {"usedParamSet":{"input":true},"params":[{"name":"input","required":true,"transform":{"type":"scalar"},"locs":[{"a":17,"b":23}]}],"statement":"SELECT pg_typeof(:input!::text[])"};
/**
* Query generated from SQL:
* ```
* SELECT pg_typeof(:input!::text[])
* ```
*/
export const example = new PreparedQuery<IExampleParams,IExampleResult>(exampleIR);
As you can see, the generated input
parameter type is problematic because it prevents us to send nullable values as parameters, although it is supported by Postgres. Having the (string)[]
type for :input!
parameter (and not (string | null)[]
) forces users to violate TS
VladimirJarabica, Shepto, stanley6631 and yakkub5