Skip to content

Commit

Permalink
Don't skip string literal types
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-mave committed Mar 18, 2024
1 parent ce8b064 commit 9e97b25
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/cli/src/parseTsPgPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 9e97b25

Please sign in to comment.