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

fix: Remove stringLiteral utility type #151

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-dogs-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gql.tada": patch
---

Remove `stringLiteral` generic constraint, causing errors depending on TypeScript version
13 changes: 5 additions & 8 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
import type { getDocumentType } from './selection';
import type { parseDocument, DocumentNodeLike } from './parser';
import type { getVariablesType, getScalarType } from './variables';
import type { stringLiteral, obj, matchOr, writable, DocumentDecoration } from './utils';
import type { obj, matchOr, writable, DocumentDecoration } from './utils';

/** Abstract configuration type input for your schema and scalars.
*
Expand Down Expand Up @@ -123,10 +123,7 @@ interface GraphQLTadaAPI<Schema extends SchemaLike, Config extends AbstractConfi
*
* @see {@link readFragment} for how to read from fragment masks.
*/
<
const In extends stringLiteral<In>,
const Fragments extends readonly [...makeDefinitionDecoration[]],
>(
<const In extends string, const Fragments extends readonly [...makeDefinitionDecoration[]]>(
input: In,
fragments?: Fragments
): getDocumentNode<
Expand Down Expand Up @@ -163,14 +160,14 @@ interface GraphQLTadaAPI<Schema extends SchemaLike, Config extends AbstractConfi
* ```
*/
scalar<
const Name extends stringLiteral<Name>,
const Name extends string,
const Value extends getScalarType<Name, Schema, null | undefined>,
>(
name: Name,
value: Value
): Value;

scalar<const Name extends stringLiteral<Name>>(
scalar<const Name extends string>(
name: Name,
value?: getScalarType<Name, Schema>
): getScalarType<Name, Schema>;
Expand Down Expand Up @@ -294,7 +291,7 @@ function initGraphQLTada<const Setup extends AbstractSetupSchema>() {
* GraphQL’s `parse` function. However, its return type will be the exact
* structure of the AST parsed in types.
*/
function parse<const In extends stringLiteral<In>>(input: In): parseDocument<In> {
function parse<const In extends string>(input: In): parseDocument<In> {
return _parse(input) as any;
}

Expand Down
3 changes: 0 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/** Constraints a given string to a string literal. */
export type stringLiteral<T extends string> = string extends T ? never : string;

/** Returns `T` if it matches `Constraint` without being equal to it. Failing this evaluates to `Fallback` otherwise. */
export type matchOr<Constraint, T, Fallback> = Constraint extends T
? Fallback
Expand Down
Loading