@isograph/react 0.0.0-main-858eda57 → 0.0.0-main-25cc6d5a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/tests/__isograph/iso.ts +31 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isograph/react",
|
|
3
|
-
"version": "0.0.0-main-
|
|
3
|
+
"version": "0.0.0-main-25cc6d5a",
|
|
4
4
|
"description": "Use Isograph with React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"prepack": "yarn run test && yarn run compile"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
20
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
|
19
|
+
"@isograph/disposable-types": "0.0.0-main-25cc6d5a",
|
|
20
|
+
"@isograph/react-disposable-state": "0.0.0-main-25cc6d5a",
|
|
21
21
|
"react": "^18.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -6,18 +6,46 @@ import entrypoint_Query__meNameSuccessor from '../__isograph/Query/meNameSuccess
|
|
|
6
6
|
import entrypoint_Query__meName from '../__isograph/Query/meName/entrypoint';
|
|
7
7
|
import entrypoint_Query__nodeField from '../__isograph/Query/nodeField/entrypoint';
|
|
8
8
|
|
|
9
|
+
// This is the type given to regular client fields.
|
|
10
|
+
// This means that the type of the exported iso literal is exactly
|
|
11
|
+
// the type of the passed-in function, which takes one parameter
|
|
12
|
+
// of type TParam.
|
|
9
13
|
type IdentityWithParam<TParam> = <TClientFieldReturn>(
|
|
10
14
|
x: (param: TParam) => TClientFieldReturn
|
|
11
15
|
) => (param: TParam) => TClientFieldReturn;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
// This is the type given it to client fields with @component.
|
|
18
|
+
// This means that the type of the exported iso literal is exactly
|
|
19
|
+
// the type of the passed-in function, which takes two parameters.
|
|
20
|
+
// The first has type TParam, and the second has type TAdditionalProps.
|
|
21
|
+
//
|
|
22
|
+
// TAdditionalProps becomes the types of the props you must pass
|
|
23
|
+
// whenever the @component field is rendered.
|
|
24
|
+
type IdentityWithParamComponent<TParam> = <TClientFieldReturn, TAdditionalProps = Record<string, never>>(
|
|
25
|
+
x: (data: TParam, secondParam: TAdditionalProps) => TClientFieldReturn
|
|
26
|
+
) => (data: TParam, secondParam: TAdditionalProps) => TClientFieldReturn;
|
|
15
27
|
|
|
16
28
|
type WhitespaceCharacter = ' ' | '\t' | '\n';
|
|
17
29
|
type Whitespace<In> = In extends `${WhitespaceCharacter}${infer In}`
|
|
18
30
|
? Whitespace<In>
|
|
19
31
|
: In;
|
|
20
32
|
|
|
33
|
+
// This is a recursive TypeScript type that matches strings that
|
|
34
|
+
// start with whitespace, followed by TString. So e.g. if we have
|
|
35
|
+
// ```
|
|
36
|
+
// export function iso<T>(
|
|
37
|
+
// param: T & MatchesWhitespaceAndString<'field Query.foo', T>
|
|
38
|
+
// ): Bar;
|
|
39
|
+
// ```
|
|
40
|
+
// then, when you call
|
|
41
|
+
// ```
|
|
42
|
+
// const x = iso(`
|
|
43
|
+
// field Query.foo ...
|
|
44
|
+
// `);
|
|
45
|
+
// ```
|
|
46
|
+
// then the type of `x` will be `Bar`, both in VSCode and when running
|
|
47
|
+
// tsc. This is how we achieve type safety — you can only use fields
|
|
48
|
+
// that you have explicitly selected.
|
|
21
49
|
type MatchesWhitespaceAndString<
|
|
22
50
|
TString extends string,
|
|
23
51
|
T
|