@process.co/element-types 0.0.1-docs
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/.github/README.md +22 -0
- package/.github/workflows/publish-element-types.yml +71 -0
- package/README.md +60 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/package.json +30 -0
- package/src/index.ts +104 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Internal Developer Notes: Element Types
|
|
2
|
+
|
|
3
|
+
This package contains shared types and utilities for Process.co elements.
|
|
4
|
+
|
|
5
|
+
- **Source:** Monorepo: [`process-co/proc-app/process-co/element-types`](https://github.com/process-co/proc-app/tree/main/process-co/element-types)
|
|
6
|
+
- **Publish Repo:** `process-co/npm-element-types`
|
|
7
|
+
- **Published to:** [npm](https://www.npmjs.com/package/@process.co/element-types)
|
|
8
|
+
- **Sync workflow:** See [`.github/workflows/sync-element-types.yml`](https://github.com/process-co/proc-app/blob/main/.github/workflows/sync%20-%20element-types.yml)
|
|
9
|
+
|
|
10
|
+
> [!IMPORTANT]
|
|
11
|
+
> CHANGES HERE WILL GET OVERWRITTEN
|
|
12
|
+
> The JS code in this repo is published from the proc-app mono repo located at https://github.com/process-co/proc-app/tree/main/process-co/element-types, the publish process bundles the specific parts of our (monorepo) internal libararies needed to run the element validataion actions
|
|
13
|
+
|
|
14
|
+
> [!WARNING]
|
|
15
|
+
> NOTHING IS MANAGED IN THIS REPO
|
|
16
|
+
> this repo is only publishing to break out code that is part of a mono repo
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Contribution
|
|
20
|
+
All changes should be made in the [`https://github.com/process-co/proc-app/process-co/element-types`](https://ghttps://github.com/process-co/proc-app/tree/main/process-co/element-types)
|
|
21
|
+
|
|
22
|
+
Contact @process-dev for questions.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: Publish Element Types
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
inputs:
|
|
8
|
+
registry:
|
|
9
|
+
description: 'NPM Registry URL'
|
|
10
|
+
required: false
|
|
11
|
+
type: string
|
|
12
|
+
default: 'https://registry.npmjs.org'
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
publish:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout repository
|
|
20
|
+
uses: actions/checkout@v3
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
|
|
24
|
+
- name: Setup Node.js
|
|
25
|
+
uses: actions/setup-node@v3
|
|
26
|
+
with:
|
|
27
|
+
node-version: 18
|
|
28
|
+
registry-url: ${{ github.event.inputs.registry || 'https://registry.npmjs.org' }}
|
|
29
|
+
|
|
30
|
+
- name: Install pnpm
|
|
31
|
+
uses: pnpm/action-setup@v2
|
|
32
|
+
with:
|
|
33
|
+
version: 10
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: pnpm install --no-frozen-lockfile
|
|
37
|
+
|
|
38
|
+
- name: Get version from tag
|
|
39
|
+
id: get_version
|
|
40
|
+
run: |
|
|
41
|
+
if [[ "${{ github.event_name }}" == "release" ]]; then
|
|
42
|
+
VERSION=${GITHUB_REF#refs/tags/}
|
|
43
|
+
VERSION=${VERSION#v}
|
|
44
|
+
else
|
|
45
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
46
|
+
fi
|
|
47
|
+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
|
48
|
+
echo "Using version: $VERSION"
|
|
49
|
+
|
|
50
|
+
- name: Update version in package.json
|
|
51
|
+
run: |
|
|
52
|
+
sed -i 's/"version": "[^"]*"/"version": "${{ steps.get_version.outputs.VERSION }}"/' package.json
|
|
53
|
+
REGISTRY="${{ github.event.inputs.registry || 'https://registry.npmjs.org' }}"
|
|
54
|
+
jq --arg reg "$REGISTRY" '.publishConfig.registry = $reg | .registry = $reg' package.json > package.json.tmp && mv package.json.tmp package.json
|
|
55
|
+
jq '.publishConfig.access = "public"' package.json > package.json.tmp && mv package.json.tmp package.json
|
|
56
|
+
|
|
57
|
+
- name: Verify package structure
|
|
58
|
+
run: |
|
|
59
|
+
echo "Checking package structure..."
|
|
60
|
+
[ -d "dist" ] || (echo "Error: dist directory missing!" && exit 1)
|
|
61
|
+
[ -f "dist/index.js" ] || (echo "Error: dist/index.js missing!" && exit 1)
|
|
62
|
+
[ -f "dist/index.d.ts" ] || (echo "Error: dist/index.d.ts missing!" && exit 1)
|
|
63
|
+
echo "dist/index.js and dist/index.d.ts found."
|
|
64
|
+
echo "Final package.json:"
|
|
65
|
+
cat package.json
|
|
66
|
+
|
|
67
|
+
- name: Publish to npm
|
|
68
|
+
run: pnpm publish --access=public --no-git-checks
|
|
69
|
+
env:
|
|
70
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
71
|
+
NPM_REGISTRY: ${{ github.event.inputs.registry || 'https://registry.npmjs.org' }}
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @process.co/element-types   
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
TypeScript types and utilities for defining Process.co Elements.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @process.co/element-types
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Pinned Version
|
|
16
|
+
```bash
|
|
17
|
+
npm install git+https://github.com/process-co/npm-element-types.git#v0.0.1
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Latest Development Version
|
|
21
|
+
```bash
|
|
22
|
+
npm install git+https://github.com/process-co/npm-element-types.git#main
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { defineApp } from '@process.co/element-types';
|
|
29
|
+
|
|
30
|
+
// Define the app
|
|
31
|
+
const exampleApp = defineApp({
|
|
32
|
+
type: "app",
|
|
33
|
+
app: "example_app",
|
|
34
|
+
props: {
|
|
35
|
+
someProp: {
|
|
36
|
+
label: "Some Prop",
|
|
37
|
+
description: "This is some prop",
|
|
38
|
+
type: "string",
|
|
39
|
+
},
|
|
40
|
+
} as const,
|
|
41
|
+
methods: {
|
|
42
|
+
async doSomthing(this: DeriveAppInstance<ExampleApp>, $: any, switchExpression: string, cases: Record<string, unknown>) {
|
|
43
|
+
// Implementation
|
|
44
|
+
return {};
|
|
45
|
+
},
|
|
46
|
+
// ... other methods
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Derive types from the implementation
|
|
51
|
+
export type ExampleApp = typeof exampleApp;
|
|
52
|
+
export type ExampleAppInstance = DeriveAppInstance<ExampleApp>;
|
|
53
|
+
|
|
54
|
+
export default processInternalApp;
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export type ElementString = {
|
|
2
|
+
type: "string";
|
|
3
|
+
label?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
};
|
|
6
|
+
export type ElementObject = {
|
|
7
|
+
type: "object";
|
|
8
|
+
label?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
};
|
|
11
|
+
export type ElementNumber = {
|
|
12
|
+
type: "number";
|
|
13
|
+
label?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
};
|
|
16
|
+
export type ElementBoolean = {
|
|
17
|
+
type: "boolean";
|
|
18
|
+
label?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
};
|
|
21
|
+
export type ElementApp<T> = {
|
|
22
|
+
type: "app";
|
|
23
|
+
app: T;
|
|
24
|
+
};
|
|
25
|
+
export type ModuleDefinition = {
|
|
26
|
+
type: string;
|
|
27
|
+
app: string;
|
|
28
|
+
propDefinitions: Record<string, unknown>;
|
|
29
|
+
methods: Record<string, (params: any) => Promise<unknown>>;
|
|
30
|
+
};
|
|
31
|
+
export type PropType<T> = T extends {
|
|
32
|
+
props: Record<string, any>;
|
|
33
|
+
methods: Record<string, any>;
|
|
34
|
+
} ? DeriveAppInstance<T> : T extends {
|
|
35
|
+
type: "string";
|
|
36
|
+
} ? string : T extends {
|
|
37
|
+
type: "object";
|
|
38
|
+
} ? Record<string, unknown> : T extends {
|
|
39
|
+
type: "number";
|
|
40
|
+
} ? number : T extends {
|
|
41
|
+
type: "boolean";
|
|
42
|
+
} ? boolean : unknown;
|
|
43
|
+
export type ModuleShape = {
|
|
44
|
+
type: string;
|
|
45
|
+
props: Record<string, any>;
|
|
46
|
+
methods: Record<string, any>;
|
|
47
|
+
};
|
|
48
|
+
export type Spread<T> = {
|
|
49
|
+
[K in keyof T]: T[K];
|
|
50
|
+
};
|
|
51
|
+
export type DeriveAppInstance<T> = T extends {
|
|
52
|
+
methods: Record<string, any>;
|
|
53
|
+
props: Record<string, any>;
|
|
54
|
+
} ? Spread<Omit<T, "props" | "methods"> & {
|
|
55
|
+
[K in keyof T["props"]]: PropType<T["props"][K]>;
|
|
56
|
+
} & {
|
|
57
|
+
[K in keyof T["methods"]]: T["methods"][K];
|
|
58
|
+
}> : never;
|
|
59
|
+
export type DeriveActionInstance<T> = T extends {
|
|
60
|
+
methods: Record<string, any>;
|
|
61
|
+
props: Record<string, any>;
|
|
62
|
+
} ? Spread<Omit<T, "props" | "methods"> & {
|
|
63
|
+
[K in keyof T["props"]]: T["props"][K] extends {
|
|
64
|
+
type: string;
|
|
65
|
+
} ? PropType<T["props"][K]> : T["props"][K] extends {
|
|
66
|
+
type: "app";
|
|
67
|
+
methods: Record<string, any>;
|
|
68
|
+
} ? {
|
|
69
|
+
[M in keyof T["props"][K]["methods"]]: T["props"][K]["methods"][M];
|
|
70
|
+
} : T["props"][K] extends {
|
|
71
|
+
methods: Record<string, any>;
|
|
72
|
+
props: Record<string, any>;
|
|
73
|
+
} ? DeriveActionInstance<T["props"][K]> : T["props"][K];
|
|
74
|
+
} & {
|
|
75
|
+
[K in keyof T["methods"]]: T["methods"][K];
|
|
76
|
+
}> : never;
|
|
77
|
+
export type ModuleWithThis<T> = T & ThisType<DeriveActionInstance<T>>;
|
|
78
|
+
export interface Action<P extends Record<string, any> = Record<string, any>> extends ModuleDefinition {
|
|
79
|
+
type: "action";
|
|
80
|
+
props: P;
|
|
81
|
+
run: (this: DeriveActionInstance<Action<P>>, params: {
|
|
82
|
+
$: any;
|
|
83
|
+
}) => Promise<unknown>;
|
|
84
|
+
}
|
|
85
|
+
export type ActionInstance<A extends Action> = DeriveActionInstance<A>;
|
|
86
|
+
export type ActionMethod<A extends Action> = (this: ActionInstance<A>, params: {
|
|
87
|
+
$: any;
|
|
88
|
+
}) => Promise<unknown>;
|
|
89
|
+
export type PropDefinition = {
|
|
90
|
+
label: string;
|
|
91
|
+
description: string;
|
|
92
|
+
type: string;
|
|
93
|
+
ui?: any;
|
|
94
|
+
};
|
|
95
|
+
export declare function defineApp<T extends object>(app: T & ThisType<DeriveAppInstance<T>>): T;
|
|
96
|
+
export declare function defineAction<T extends object>(action: T & ThisType<DeriveActionInstance<T>>): T;
|
|
97
|
+
export type WithThis<T> = T extends {
|
|
98
|
+
methods: Record<string, any>;
|
|
99
|
+
props: Record<string, any>;
|
|
100
|
+
} ? Omit<T, 'methods'> & {
|
|
101
|
+
methods: {
|
|
102
|
+
[K in keyof T['methods']]: T['methods'][K] extends (...args: infer A) => infer R ? (this: DeriveActionInstance<T>, ...args: A) => R : T['methods'][K];
|
|
103
|
+
};
|
|
104
|
+
} : T;
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAC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;CAAE,GAC5F,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG;IACrB,OAAO,EAAE;SACN,CAAC,IAAI,MAAM,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAC9E,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAChD,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KAClB,CAAC;CACH,GACC,CAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineApp = defineApp;
|
|
4
|
+
exports.defineAction = defineAction;
|
|
5
|
+
// Helper to provide ThisType context for app definitions
|
|
6
|
+
function defineApp(app) {
|
|
7
|
+
return app;
|
|
8
|
+
}
|
|
9
|
+
// Helper to provide ThisType context for action definitions
|
|
10
|
+
function defineAction(action) {
|
|
11
|
+
return action;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFxRkEsOEJBRUM7QUFHRCxvQ0FFQztBQVJELHlEQUF5RDtBQUN6RCxTQUFnQixTQUFTLENBQW1CLEdBQXVDO0lBQ2pGLE9BQU8sR0FBRyxDQUFDO0FBQ2IsQ0FBQztBQUVELDREQUE0RDtBQUM1RCxTQUFnQixZQUFZLENBQW1CLE1BQTZDO0lBQzFGLE9BQU8sTUFBTSxDQUFDO0FBQ2hCLENBQUMifQ==
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@process.co/element-types",
|
|
3
|
+
"version": "0.0.1-docs",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/process-co/npm-element-types.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org",
|
|
13
|
+
"scope": "@process.co"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"process",
|
|
17
|
+
"element",
|
|
18
|
+
"types",
|
|
19
|
+
"validation"
|
|
20
|
+
],
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Process.co Team",
|
|
23
|
+
"email": "developers@process.co"
|
|
24
|
+
},
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"registry": "https://registry.npmjs.org",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Element types
|
|
2
|
+
export type ElementString = { type: "string"; label?: string; description?: string };
|
|
3
|
+
export type ElementObject = { type: "object"; label?: string; description?: string };
|
|
4
|
+
export type ElementNumber = { type: "number"; label?: string; description?: string };
|
|
5
|
+
export type ElementBoolean = { type: "boolean"; label?: string; description?: string };
|
|
6
|
+
export type ElementApp<T> = { type: "app"; app: T };
|
|
7
|
+
|
|
8
|
+
// Base types for module definitions
|
|
9
|
+
export type ModuleDefinition = {
|
|
10
|
+
type: string;
|
|
11
|
+
app: string;
|
|
12
|
+
propDefinitions: Record<string, unknown>;
|
|
13
|
+
methods: Record<string, (params: any) => Promise<unknown>>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Utility type for transforming prop definitions to their runtime types
|
|
17
|
+
export type PropType<T> =
|
|
18
|
+
T extends { props: Record<string, any>; methods: Record<string, any> }
|
|
19
|
+
? DeriveAppInstance<T>
|
|
20
|
+
: T extends { type: "string" } ? string
|
|
21
|
+
: T extends { type: "object" } ? Record<string, unknown>
|
|
22
|
+
: T extends { type: "number" } ? number
|
|
23
|
+
: T extends { type: "boolean" } ? boolean
|
|
24
|
+
: unknown;
|
|
25
|
+
|
|
26
|
+
// Base module shape type
|
|
27
|
+
export type ModuleShape = {
|
|
28
|
+
type: string;
|
|
29
|
+
props: Record<string, any>;
|
|
30
|
+
methods: Record<string, any>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Utility type to force flattening of intersections
|
|
34
|
+
export type Spread<T> = { [K in keyof T]: T[K] };
|
|
35
|
+
|
|
36
|
+
// Helper type to derive instance type from app definition, fully flattened
|
|
37
|
+
export type DeriveAppInstance<T> =
|
|
38
|
+
T extends { methods: Record<string, any>; props: Record<string, any> }
|
|
39
|
+
? Spread<
|
|
40
|
+
Omit<T, "props" | "methods"> &
|
|
41
|
+
{ [K in keyof T["props"]]: PropType<T["props"][K]> } &
|
|
42
|
+
{ [K in keyof T["methods"]]: T["methods"][K] }
|
|
43
|
+
>
|
|
44
|
+
: never;
|
|
45
|
+
|
|
46
|
+
// Helper type to derive instance type from action/source definition, fully flattened
|
|
47
|
+
export type DeriveActionInstance<T> =
|
|
48
|
+
T extends { methods: Record<string, any>; props: Record<string, any> }
|
|
49
|
+
? Spread<
|
|
50
|
+
Omit<T, "props" | "methods"> &
|
|
51
|
+
{ [K in keyof T["props"]]: T["props"][K] extends { type: string }
|
|
52
|
+
? PropType<T["props"][K]>
|
|
53
|
+
: T["props"][K] extends { type: "app"; methods: Record<string, any> }
|
|
54
|
+
? { [M in keyof T["props"][K]["methods"]]: T["props"][K]["methods"][M] }
|
|
55
|
+
: T["props"][K] extends { methods: Record<string, any>; props: Record<string, any> }
|
|
56
|
+
? DeriveActionInstance<T["props"][K]>
|
|
57
|
+
: T["props"][K]
|
|
58
|
+
} &
|
|
59
|
+
{ [K in keyof T["methods"]]: T["methods"][K] }
|
|
60
|
+
>
|
|
61
|
+
: never;
|
|
62
|
+
|
|
63
|
+
// Helper type to create a module with proper this context
|
|
64
|
+
export type ModuleWithThis<T> = T & ThisType<DeriveActionInstance<T>>;
|
|
65
|
+
|
|
66
|
+
// Action-specific types
|
|
67
|
+
export interface Action<P extends Record<string, any> = Record<string, any>> extends ModuleDefinition {
|
|
68
|
+
type: "action";
|
|
69
|
+
props: P;
|
|
70
|
+
run: (this: DeriveActionInstance<Action<P>>, params: { $: any }) => Promise<unknown>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type ActionInstance<A extends Action> = DeriveActionInstance<A>;
|
|
74
|
+
|
|
75
|
+
export type ActionMethod<A extends Action> = (this: ActionInstance<A>, params: { $: any }) => Promise<unknown>;
|
|
76
|
+
|
|
77
|
+
// Prop definition type
|
|
78
|
+
export type PropDefinition = {
|
|
79
|
+
label: string;
|
|
80
|
+
description: string;
|
|
81
|
+
type: string;
|
|
82
|
+
ui?: any;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Helper to provide ThisType context for app definitions
|
|
86
|
+
export function defineApp<T extends object>(app: T & ThisType<DeriveAppInstance<T>>): T {
|
|
87
|
+
return app;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Helper to provide ThisType context for action definitions
|
|
91
|
+
export function defineAction<T extends object>(action: T & ThisType<DeriveActionInstance<T>>): T {
|
|
92
|
+
return action;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Utility type to automatically infer the correct this context for methods
|
|
96
|
+
export type WithThis<T> = T extends { methods: Record<string, any>; props: Record<string, any> }
|
|
97
|
+
? Omit<T, 'methods'> & {
|
|
98
|
+
methods: {
|
|
99
|
+
[K in keyof T['methods']]: T['methods'][K] extends (...args: infer A) => infer R
|
|
100
|
+
? (this: DeriveActionInstance<T>, ...args: A) => R
|
|
101
|
+
: T['methods'][K];
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
: T;
|