Skip to content

Commit 85c667e

Browse files
authored
Add const to Values type parameter on g.enum (#59)
1 parent a7336ff commit 85c667e

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

.changeset/loud-fishes-unite.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-ts/schema": patch
3+
---
4+
5+
Add `const` to `Values` type parameter on `g.enum` to improve inference

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ dist
103103
# TernJS port file
104104
.tern-port
105105

106-
.vitepress/cache
106+
site/.vitepress/cache

packages/schema/src/output.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ export type GWithContext<Context> = {
603603
* `;)
604604
* ```
605605
*/
606-
enum: <Values extends Record<string, unknown>>(
606+
enum: <const Values extends Record<string, unknown>>(
607607
config: GEnumTypeConfig<Values>
608608
) => GEnumType<Values>;
609609
/**

test-project/index.test-d.ts

+18
Original file line numberDiff line numberDiff line change
@@ -2162,3 +2162,21 @@ const someInputFields = {
21622162
},
21632163
});
21642164
}
2165+
2166+
{
2167+
const x = g.enum({
2168+
name: "X",
2169+
values: {
2170+
a: {
2171+
value: "a",
2172+
},
2173+
b: {
2174+
value: "b",
2175+
},
2176+
},
2177+
});
2178+
assertCompatible<
2179+
Invariant<GEnumType<{ a: "a"; b: "b" }>>,
2180+
Invariant<typeof x>
2181+
>();
2182+
}

0 commit comments

Comments
 (0)