UNPKG

1.05 kBPlain TextView Raw
1import type { Args } from './Args.js'
2import type { MaybeThunk } from './core/helpers.js'
3import type { Hybrid } from './Hybrid/__.js'
4import type { Output } from './Output/__.js'
5
6export type Field<$Type extends Output.Any, $Args extends Args<any> | null> = {
7 type: $Type
8 args: $Args
9}
10
11export const field = <$Type extends Output.Any, $Args extends null | Args<any> = null>(
12 type: MaybeThunk<$Type>,
13 args: $Args = null as $Args,
14): Field<$Type, $Args> => {
15 return {
16 // At type level "type" is not a thunk
17 type: type as any, // eslint-disable-line
18 args,
19 }
20}
21
22// todo test non null interface fields
23export type SomeField = Field<
24 | Hybrid.Enum
25 | Hybrid.Scalar.Any
26 | Output.List<any>
27 | Output.Nullable<any>
28 | Output.Object$2<string, any>
29 | Output.Union<string, [any, ...any[]]>
30 | Output.Interface<string, Record<string, Field<any, Args<any> | null>>, [any, ...any[]]>,
31 Args<any> | null
32>
33
34export type SomeFields<$Keys extends string | number | symbol = string | number | symbol> = Record<
35 $Keys,
36 SomeField
37>