From 9e97b25e26eaebc9e2124d25d64e0dbc7916c02c Mon Sep 17 00:00:00 2001 From: Mika Lehtinen Date: Mon, 18 Mar 2024 17:16:23 +0200 Subject: [PATCH] Don't skip string literal types --- packages/cli/src/parseTsPgPromise.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/parseTsPgPromise.ts b/packages/cli/src/parseTsPgPromise.ts index e541e446..a88b95d6 100644 --- a/packages/cli/src/parseTsPgPromise.ts +++ b/packages/cli/src/parseTsPgPromise.ts @@ -190,10 +190,9 @@ function parseFile( const queryType = checker.getTypeAtLocation(res.queryArgument); // TS computes a template literal containing only union literal placeholders to a union of literals if ( - queryType.flags & ts.TypeFlags.Union && - (queryType as ts.UnionType).types.every( - (t) => t.flags & ts.TypeFlags.StringLiteral, - ) + (queryType.isUnion() && + queryType.types.every((t) => t.isStringLiteral())) || + queryType.isStringLiteral() ) { foundNodes.push({ queryName: baseName, @@ -223,13 +222,12 @@ function parseFile( } function typeToStringOrStringArray(type: ts.Type) { - if (type.flags & ts.TypeFlags.Union) { - const r = type as ts.UnionType; - if (r.types.every((t) => t.flags & ts.TypeFlags.StringLiteral)) { - return r.types.map((t) => (t as ts.StringLiteralType).value); + if (type.isUnion()) { + if (type.types.every((t) => t.isStringLiteral())) { + return type.types.map((t) => (t as ts.StringLiteralType).value); } - } else if (type.flags & ts.TypeFlags.StringLiteral) { - return (type as ts.StringLiteralType).value; + } else if (type.isStringLiteral()) { + return type.value; } throw Error( 'Expected type to be either a string literal or a union of string literals',