react-hook-form 7.26.1 → 8.0.0-alpha.1
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/dist/__typetests__/__fixtures__/index.d.ts +2 -0
- package/dist/__typetests__/__fixtures__/index.d.ts.map +1 -0
- package/dist/__typetests__/__fixtures__/type.d.ts +12 -0
- package/dist/__typetests__/__fixtures__/type.d.ts.map +1 -0
- package/dist/__typetests__/types/__fixtures__/index.d.ts +4 -0
- package/dist/__typetests__/types/__fixtures__/index.d.ts.map +1 -0
- package/dist/__typetests__/types/__fixtures__/pathString.d.ts +4 -0
- package/dist/__typetests__/types/__fixtures__/pathString.d.ts.map +1 -0
- package/dist/__typetests__/types/__fixtures__/traversable.d.ts +14 -0
- package/dist/__typetests__/types/__fixtures__/traversable.d.ts.map +1 -0
- package/dist/__typetests__/types/__fixtures__/tuple.d.ts +15 -0
- package/dist/__typetests__/types/__fixtures__/tuple.d.ts.map +1 -0
- package/dist/__typetests__/types/form.test-d.d.ts +2 -0
- package/dist/__typetests__/types/form.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/auto.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/auto.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/autoCompletePath.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/autoCompletePath.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/hasPath.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/hasPath.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/keys.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/keys.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/pathGetValue.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/pathGetValue.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/pathSetValue.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/pathSetValue.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/pathTuple.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/pathTuple.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/internal/utils.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/internal/utils.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/lazy.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/lazy.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/path/value.test-d.d.ts +2 -0
- package/dist/__typetests__/types/path/value.test-d.d.ts.map +1 -0
- package/dist/__typetests__/types/util.test-d.d.ts +2 -0
- package/dist/__typetests__/types/util.test-d.d.ts.map +1 -0
- package/dist/__typetests__/utils/join.test-d.d.ts +2 -0
- package/dist/__typetests__/utils/join.test-d.d.ts.map +1 -0
- package/dist/__typetests__/utils/of.test-d.d.ts +2 -0
- package/dist/__typetests__/utils/of.test-d.d.ts.map +1 -0
- package/dist/controller.d.ts +1 -1
- package/dist/controller.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +47 -33
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/logic/getResolverOptions.d.ts +2 -2
- package/dist/logic/hasValidation.d.ts +1 -1
- package/dist/types/controller.d.ts +8 -8
- package/dist/types/controller.d.ts.map +1 -1
- package/dist/types/errors.d.ts +8 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/fieldArray.d.ts +12 -13
- package/dist/types/fieldArray.d.ts.map +1 -1
- package/dist/types/form.d.ts +44 -50
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/path/auto.d.ts +76 -0
- package/dist/types/path/auto.d.ts.map +1 -0
- package/dist/types/path/branded.d.ts +61 -0
- package/dist/types/path/branded.d.ts.map +1 -0
- package/dist/types/path/index.d.ts +7 -3
- package/dist/types/path/index.d.ts.map +1 -1
- package/dist/types/path/internal/autoCompletePath.d.ts +173 -0
- package/dist/types/path/internal/autoCompletePath.d.ts.map +1 -0
- package/dist/types/path/internal/hasPath.d.ts +56 -0
- package/dist/types/path/internal/hasPath.d.ts.map +1 -0
- package/dist/types/path/internal/keys.d.ts +103 -0
- package/dist/types/path/internal/keys.d.ts.map +1 -0
- package/dist/types/path/internal/pathGetValue.d.ts +76 -0
- package/dist/types/path/internal/pathGetValue.d.ts.map +1 -0
- package/dist/types/path/internal/pathSetValue.d.ts +96 -0
- package/dist/types/path/internal/pathSetValue.d.ts.map +1 -0
- package/dist/types/path/internal/pathTuple.d.ts +73 -0
- package/dist/types/path/internal/pathTuple.d.ts.map +1 -0
- package/dist/types/path/internal/utils.d.ts +84 -0
- package/dist/types/path/internal/utils.d.ts.map +1 -0
- package/dist/types/path/lazy.d.ts +62 -0
- package/dist/types/path/lazy.d.ts.map +1 -0
- package/dist/types/path/pathString.d.ts +6 -0
- package/dist/types/path/pathString.d.ts.map +1 -0
- package/dist/types/path/value.d.ts +49 -0
- package/dist/types/path/value.d.ts.map +1 -0
- package/dist/types/resolvers.d.ts +3 -3
- package/dist/types/resolvers.d.ts.map +1 -1
- package/dist/types/utils.d.ts +15 -7
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/validator.d.ts +2 -2
- package/dist/types/validator.d.ts.map +1 -1
- package/dist/useController.d.ts +2 -2
- package/dist/useController.d.ts.map +1 -1
- package/dist/useFieldArray.d.ts +2 -2
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/useForm.d.ts +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useFormContext.d.ts +2 -2
- package/dist/useFormContext.d.ts.map +1 -1
- package/dist/useFormState.d.ts +2 -2
- package/dist/useFormState.d.ts.map +1 -1
- package/dist/useWatch.d.ts +9 -23
- package/dist/useWatch.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/join.d.ts +16 -0
- package/dist/utils/join.d.ts.map +1 -0
- package/dist/utils/of.d.ts +13 -0
- package/dist/utils/of.d.ts.map +1 -0
- package/dist/utils/unset.d.ts.map +1 -1
- package/package.json +15 -15
- package/dist/types/path/common.d.ts +0 -316
- package/dist/types/path/common.d.ts.map +0 -1
- package/dist/types/path/eager.d.ts +0 -82
- package/dist/types/path/eager.d.ts.map +0 -1
- package/dist/utils/omitKeys.d.ts +0 -3
- package/dist/utils/omitKeys.d.ts.map +0 -1
@@ -0,0 +1,76 @@
|
|
1
|
+
import { FieldValues } from '../fields';
|
2
|
+
import * as Branded from './branded';
|
3
|
+
import * as Lazy from './lazy';
|
4
|
+
import { PathString } from './pathString';
|
5
|
+
/**
|
6
|
+
* Type which offers autocompletion of paths through a form.
|
7
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
8
|
+
* @typeParam TPathString - the string representation of the path
|
9
|
+
* @typeParam TValue - the value which may be read from the path
|
10
|
+
* @typeParam TValueSet - the value which can be written to the path
|
11
|
+
* @example
|
12
|
+
* ```
|
13
|
+
* declare function getNumber<T extends FieldValues, P extends PathString>(
|
14
|
+
* obj: T,
|
15
|
+
* path: TypedFieldPath<T, P, number>,
|
16
|
+
* ): number
|
17
|
+
* ```
|
18
|
+
*/
|
19
|
+
export declare type TypedFieldPath<TFieldValues, TPathString extends PathString, TValue, TValueSet = TValue> = Branded.TypedFieldPath<TFieldValues, TValue, TValueSet> | Lazy.TypedFieldPath<TFieldValues, TPathString, TValue, TValueSet>;
|
20
|
+
/**
|
21
|
+
* Type which offers autocompletion of paths through a form.
|
22
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
23
|
+
* @typeParam TPathString - the string representation of the path
|
24
|
+
* @example
|
25
|
+
* ```
|
26
|
+
* declare function get<T extends FieldValues, P extends PathString>(
|
27
|
+
* obj: T,
|
28
|
+
* path: FieldPath<T, P>,
|
29
|
+
* ): FieldPathValue<T, P>
|
30
|
+
* ```
|
31
|
+
*/
|
32
|
+
export declare type FieldPath<TFieldValues, TPathString extends PathString> = Branded.FieldPath<TFieldValues> | Lazy.FieldPath<TFieldValues, TPathString>;
|
33
|
+
/**
|
34
|
+
* Type which offers autocompletion of paths through a form which point to an array.
|
35
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
36
|
+
* @typeParam TPathString - the string representation of the path
|
37
|
+
* @typeParam TArrayValues - the value which may be read from array at the path
|
38
|
+
* @typeParam TArrayValuesSet - the value which can be written to the array at the path
|
39
|
+
* @example
|
40
|
+
* ```
|
41
|
+
* declare function popNumber<T extends FieldValues, P extends PathString>(
|
42
|
+
* obj: T,
|
43
|
+
* path: TypedFieldArrayPath<T, P, number>,
|
44
|
+
* ): number
|
45
|
+
* ```
|
46
|
+
*/
|
47
|
+
export declare type TypedFieldArrayPath<TFieldValues, TPathString extends PathString, TArrayValues extends FieldValues, TArrayValuesSet extends FieldValues = TArrayValues> = Branded.TypedFieldArrayPath<TFieldValues, TArrayValues, TArrayValuesSet> | Lazy.TypedFieldArrayPath<TFieldValues, TPathString, TArrayValues, TArrayValuesSet>;
|
48
|
+
/**
|
49
|
+
* Type which offers autocompletion of paths through a form which point to an array.
|
50
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
51
|
+
* @typeParam TPathString - the string representation of the path
|
52
|
+
* @example
|
53
|
+
* ```
|
54
|
+
* declare function pop<T extends FieldValues, P extends PathString>(
|
55
|
+
* obj: T,
|
56
|
+
* path: FieldArrayPath<T, P>,
|
57
|
+
* ): FieldPathValue<T, P>[never]
|
58
|
+
* ```
|
59
|
+
*/
|
60
|
+
export declare type FieldArrayPath<TFieldValues, TPathString extends PathString> = Branded.FieldArrayPath<TFieldValues> | Lazy.FieldArrayPath<TFieldValues, TPathString>;
|
61
|
+
/**
|
62
|
+
* Type which offers autocompletion for a tuple of paths through a form.
|
63
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
64
|
+
* @typeParam TPathStrings - the string representations of the paths
|
65
|
+
* @example
|
66
|
+
* ```
|
67
|
+
* declare function get<
|
68
|
+
* T extends FieldValues,
|
69
|
+
* P extends ReadonlyArray<PathString>,
|
70
|
+
* >(obj: T, paths: FieldPaths<T, P>): FieldPathValues<T, P>
|
71
|
+
* ```
|
72
|
+
*/
|
73
|
+
export declare type FieldPaths<TFieldValues, TPathStrings extends ReadonlyArray<PathString>> = {
|
74
|
+
[Idx in keyof TPathStrings]: FieldPath<TFieldValues, Extract<TPathStrings[Idx], PathString>>;
|
75
|
+
};
|
76
|
+
//# sourceMappingURL=auto.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"auto.d.ts","sourceRoot":"","sources":["../../../src/types/path/auto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,oBAAY,cAAc,CACxB,YAAY,EACZ,WAAW,SAAS,UAAU,EAC9B,MAAM,EACN,SAAS,GAAG,MAAM,IAEhB,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,GACvD,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,oBAAY,SAAS,CAAC,YAAY,EAAE,WAAW,SAAS,UAAU,IAC9D,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,GAC/B,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,oBAAY,mBAAmB,CAC7B,YAAY,EACZ,WAAW,SAAS,UAAU,EAC9B,YAAY,SAAS,WAAW,EAChC,eAAe,SAAS,WAAW,GAAG,YAAY,IAEhD,OAAO,CAAC,mBAAmB,CAAC,YAAY,EAAE,YAAY,EAAE,eAAe,CAAC,GACxE,IAAI,CAAC,mBAAmB,CACtB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,eAAe,CAChB,CAAC;AAEN;;;;;;;;;;;GAWG;AACH,oBAAY,cAAc,CAAC,YAAY,EAAE,WAAW,SAAS,UAAU,IACnE,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,GACpC,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,oBAAY,UAAU,CACpB,YAAY,EACZ,YAAY,SAAS,aAAa,CAAC,UAAU,CAAC,IAC5C;KACD,GAAG,IAAI,MAAM,YAAY,GAAG,SAAS,CACpC,YAAY,EACZ,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CACvC;CACF,CAAC"}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import { FieldValues } from '../fields';
|
2
|
+
import { AccessPattern } from './internal/utils';
|
3
|
+
declare const FORM_VALUES: unique symbol;
|
4
|
+
declare const ACCESS_PATTERN: unique symbol;
|
5
|
+
/**
|
6
|
+
* Type which describes a path through a form.
|
7
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
8
|
+
* @typeParam TValue - the value which may be read from the path
|
9
|
+
* @typeParam TValueSet - the value which can be written to the path
|
10
|
+
* @example
|
11
|
+
* ```
|
12
|
+
* declare function getNumber<T extends FieldValues>(
|
13
|
+
* obj: T,
|
14
|
+
* path: TypedFieldPath<T, number>,
|
15
|
+
* ): number
|
16
|
+
* ```
|
17
|
+
*/
|
18
|
+
export declare type TypedFieldPath<TFieldValues, TValue, TValueSet = TValue> = string & {
|
19
|
+
[FORM_VALUES]: TFieldValues;
|
20
|
+
[ACCESS_PATTERN]: AccessPattern<TValue, TValueSet>;
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* Type which describes a path through a form.
|
24
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
25
|
+
* @example
|
26
|
+
* ```
|
27
|
+
* declare function get<T extends FieldValues, P extends FieldPath<T>>(
|
28
|
+
* obj: T,
|
29
|
+
* path: P,
|
30
|
+
* ): FieldPathValue<T, P>
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
export declare type FieldPath<TFieldValues> = TypedFieldPath<TFieldValues, unknown, never>;
|
34
|
+
/**
|
35
|
+
* Type which describes a path through a form and points to an array.
|
36
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
37
|
+
* @typeParam TArrayValues - the value which may be read from array at the path
|
38
|
+
* @typeParam TArrayValuesSet - the value which can be written to the array at the path
|
39
|
+
* @example
|
40
|
+
* ```
|
41
|
+
* declare function popNumber<T extends FieldValues>(
|
42
|
+
* obj: T,
|
43
|
+
* path: TypedFieldArrayPath<T, number>,
|
44
|
+
* ): number
|
45
|
+
* ```
|
46
|
+
*/
|
47
|
+
export declare type TypedFieldArrayPath<TFieldValues, TArrayValues extends FieldValues, TArrayValuesSet extends FieldValues = TArrayValues> = TypedFieldPath<TFieldValues, ReadonlyArray<TArrayValues> | null | undefined, TArrayValuesSet[]>;
|
48
|
+
/**
|
49
|
+
* Type which describes a path through a form and points to an array.
|
50
|
+
* @typeParam TFieldValues - the field values for which this path is valid
|
51
|
+
* @example
|
52
|
+
* ```
|
53
|
+
* declare function pop<T extends FieldValues, P extends FieldArrayPath<T>>(
|
54
|
+
* obj: T,
|
55
|
+
* path: P,
|
56
|
+
* ): FieldPathValue<T, P>[never]
|
57
|
+
* ```
|
58
|
+
*/
|
59
|
+
export declare type FieldArrayPath<TFieldValues> = TypedFieldArrayPath<TFieldValues, FieldValues, never>;
|
60
|
+
export {};
|
61
|
+
//# sourceMappingURL=branded.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../../../src/types/path/branded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AACzC,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,oBAAY,cAAc,CACxB,YAAY,EACZ,MAAM,EACN,SAAS,GAAG,MAAM,IAChB,MAAM,GAAG;IACX,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC5B,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,oBAAY,SAAS,CAAC,YAAY,IAAI,cAAc,CAClD,YAAY,EACZ,OAAO,EACP,KAAK,CACN,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,oBAAY,mBAAmB,CAC7B,YAAY,EACZ,YAAY,SAAS,WAAW,EAChC,eAAe,SAAS,WAAW,GAAG,YAAY,IAChD,cAAc,CAChB,YAAY,EACZ,aAAa,CAAC,YAAY,CAAC,GAAG,IAAI,GAAG,SAAS,EAC9C,eAAe,EAAE,CAClB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,oBAAY,cAAc,CAAC,YAAY,IAAI,mBAAmB,CAC5D,YAAY,EACZ,WAAW,EACX,KAAK,CACN,CAAC"}
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import type * as Auto from './auto';
|
2
|
+
import type * as Branded from './branded';
|
3
|
+
import type * as Lazy from './lazy';
|
4
|
+
export type { Auto, Branded, Lazy };
|
5
|
+
export * from './branded';
|
6
|
+
export * from './pathString';
|
7
|
+
export * from './value';
|
4
8
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/path/index.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/path/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,KAAK,OAAO,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,KAAK,IAAI,MAAM,QAAQ,CAAC;AAEpC,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
@@ -0,0 +1,173 @@
|
|
1
|
+
import { IsAny, IsNever } from '../../utils';
|
2
|
+
import { PathString } from '../pathString';
|
3
|
+
import { HasPath, ValidPathPrefix } from './hasPath';
|
4
|
+
import { Keys } from './keys';
|
5
|
+
import { PathGetValue } from './pathGetValue';
|
6
|
+
import { PathSetValue } from './pathSetValue';
|
7
|
+
import { JoinPathTuple, PathTuple, SplitPathString } from './pathTuple';
|
8
|
+
import { AccessPattern, Key, Traversable, UnionToIntersection } from './utils';
|
9
|
+
/**
|
10
|
+
* Type, which given a path, returns the parent path as a string
|
11
|
+
* @typeParam PT - path represented as a tuple
|
12
|
+
* @example
|
13
|
+
* ```
|
14
|
+
* SuggestParentPath<['foo', 'bar', 'baz']> = 'foo.bar'
|
15
|
+
* SuggestParentPath<['foo', 'bar']> = 'foo'
|
16
|
+
* SuggestParentPath<['foo']> = never
|
17
|
+
* ```
|
18
|
+
* @internal
|
19
|
+
*/
|
20
|
+
export declare type SuggestParentPath<PT extends PathTuple> = JoinPathTuple<PT extends [...infer R, Key] ? R : []>;
|
21
|
+
/**
|
22
|
+
* Type to implement {@link SuggestChildPaths}.
|
23
|
+
* @typeParam PT - the current path as a {@link PathTuple}
|
24
|
+
* @typeParam TPT - the type at that path
|
25
|
+
* @typeParam C - constraint
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
declare type SuggestChildPathsImpl<PT extends PathTuple, TPT, C extends AccessPattern> = JoinPathTuple<[
|
29
|
+
...PT,
|
30
|
+
Keys<TPT, C> | Keys<TPT, AccessPattern<Traversable | undefined | null>>
|
31
|
+
]>;
|
32
|
+
/**
|
33
|
+
* Type, which given a type and a path into the type, returns all paths as
|
34
|
+
* strings which can be used to index the type at that path.
|
35
|
+
* Filters out paths whose value doesn't match the constraint type or
|
36
|
+
* aren't traversable.
|
37
|
+
* @typeParam T - type which is indexed by the path
|
38
|
+
* @typeParam PT - the current path into the type as a tuple
|
39
|
+
* @typeParam C - constraint
|
40
|
+
* @example
|
41
|
+
* ```
|
42
|
+
* SuggestChildPaths<{foo: string, bar: string}, [], AccessPattern<string>>
|
43
|
+
* = 'foo' | 'bar'
|
44
|
+
* SuggestChildPaths<{foo: string, bar: number}, [], AccessPattern<string>>
|
45
|
+
* = 'foo'
|
46
|
+
* SuggestChildPaths<{foo: {bar: string}}, ['foo']> = 'foo.bar'
|
47
|
+
* SuggestChildPaths<{foo: {bar: string[]}}, ['foo']> = 'foo.bar'
|
48
|
+
* ```
|
49
|
+
* @internal
|
50
|
+
*/
|
51
|
+
export declare type SuggestChildPaths<T, PT extends PathTuple, C extends AccessPattern = AccessPattern> = PT extends any ? SuggestChildPathsImpl<PT, PathGetValue<T, PT>, C> : never;
|
52
|
+
/**
|
53
|
+
* Type to implement {@link SuggestPaths} without having to compute the valid
|
54
|
+
* path prefix more than once.
|
55
|
+
* @typeParam T - type which is indexed by the path
|
56
|
+
* @typeParam PT - the current path into the type as a tuple
|
57
|
+
* @typeParam C - constraint
|
58
|
+
* @typeParam VPT - the valid path prefix for the given path
|
59
|
+
* @internal
|
60
|
+
*/
|
61
|
+
declare type SuggestPathsImpl<T, PT extends PathTuple, C extends AccessPattern, VPT extends PathTuple> = SuggestChildPaths<T, VPT, C> | (PT extends VPT ? SuggestParentPath<VPT> : JoinPathTuple<VPT>);
|
62
|
+
/**
|
63
|
+
* Type which given a type and a path tuple into it returns
|
64
|
+
* - its parent/predecessor path string.
|
65
|
+
* - all its child/successor paths that point to a type which is either
|
66
|
+
* traversable or matches the constraint type.
|
67
|
+
* In case the path does not exist it returns all of the above, but for the last
|
68
|
+
* valid path prefix.
|
69
|
+
* @typeParam T - type which is indexed by the path
|
70
|
+
* @typeParam PT - the current path into the type as a tuple
|
71
|
+
* @typeParam C - constraint
|
72
|
+
* @example
|
73
|
+
* ```
|
74
|
+
* SuggestPaths<{foo: {bar: string}}, ['foo'], string> = 'foo.bar'
|
75
|
+
* SuggestPaths<{foo: {bar: string}}, ['foo', 'ba'], AccessPattern<string>>
|
76
|
+
* = 'foo' | 'foo.bar'
|
77
|
+
* SuggestPaths<{foo: {bar: string}}, ['foo', 'bar'], AccessPattern<string>>
|
78
|
+
* = 'foo'
|
79
|
+
* SuggestPaths<{foo: {bar: {baz: string}}}, ['foo', 'bar'], AccessPattern<string>>
|
80
|
+
* = 'foo' | 'foo.bar.baz'
|
81
|
+
* ```
|
82
|
+
* @internal
|
83
|
+
*/
|
84
|
+
export declare type SuggestPaths<T, PT extends PathTuple, C extends AccessPattern = AccessPattern> = SuggestPathsImpl<T, PT, C, ValidPathPrefix<T, PT>>;
|
85
|
+
/**
|
86
|
+
* Type to test whether the path is a union of paths.
|
87
|
+
* @typeParam PS - path
|
88
|
+
* @example
|
89
|
+
* ```
|
90
|
+
* IsPathUnion<'foo'> = false
|
91
|
+
* IsPathUnion<'foo' | 'foo'> = false
|
92
|
+
* IsPathUnion<'foo' | 'foo.bar'> = true
|
93
|
+
* ```
|
94
|
+
* @internal
|
95
|
+
*/
|
96
|
+
declare type IsPathUnion<PS extends PathString> = IsNever<UnionToIntersection<PS>>;
|
97
|
+
/**
|
98
|
+
* Type to check the current path against the constraint type.
|
99
|
+
* Returns the path if it is valid and matches the constraint type.
|
100
|
+
* @typeParam T - type which is indexed by the path
|
101
|
+
* @typeParam PS - the current path into the type as a string,
|
102
|
+
* mustn't be a union
|
103
|
+
* @typeParam PT - the current path into the type as a tuple,
|
104
|
+
* must be equal to SplitPathString<PS>
|
105
|
+
* @typeParam C - constraint
|
106
|
+
* @example
|
107
|
+
* ```
|
108
|
+
* AutoCompletePathCheckConstraint<{foo: {bar: string}}, 'foo', ['foo'], AccessPattern<string>>
|
109
|
+
* = never
|
110
|
+
* AutoCompletePathCheckConstraint<{foo: {bar: string}}, 'foo.ba', ['foo', 'ba'], AccessPattern<string>>
|
111
|
+
* = never
|
112
|
+
* AutoCompletePathCheckConstraint<{foo: {bar: string}}, 'foo.bar', ['foo', 'bar'], AccessPattern<string>>
|
113
|
+
* = 'foo.bar'
|
114
|
+
* ```
|
115
|
+
* @internal
|
116
|
+
*/
|
117
|
+
declare type AutoCompletePathCheckConstraint<T, PS extends PathString, PT extends PathTuple, C extends AccessPattern> = HasPath<T, PT> extends true ? AccessPattern<PathGetValue<T, PT>, PathSetValue<T, PT>> extends C ? PS extends JoinPathTuple<PT> ? PS : JoinPathTuple<PT> : never : never;
|
118
|
+
/**
|
119
|
+
* Type to implement {@link AutoCompletePath} without having to compute the
|
120
|
+
* path tuple more than once.
|
121
|
+
* @typeParam T - type which is indexed by the path
|
122
|
+
* @typeParam PS - the current path into the type as a string,
|
123
|
+
* mustn't be a union
|
124
|
+
* @typeParam PT - the current path into the type as a tuple,
|
125
|
+
* must be equal to SplitPathString<PS>
|
126
|
+
* @typeParam C - constraint
|
127
|
+
* @example
|
128
|
+
* ```
|
129
|
+
* AutoCompletePathImpl<{foo: {bar: string}}, 'foo', ['foo'], AccessPattern<string>>
|
130
|
+
* = 'foo.bar'
|
131
|
+
* AutoCompletePathImpl<{foo: {bar: string}}, 'foo.ba', ['foo', 'ba'], AccessPattern<string>>
|
132
|
+
* = 'foo' | 'foo.bar'
|
133
|
+
* AutoCompletePathImpl<{foo: {bar: string}}, 'foo.bar', ['foo', 'bar'], AccessPattern<string>>
|
134
|
+
* = 'foo' | 'foo.bar'
|
135
|
+
* AutoCompletePathImpl<{foo: {bar: {baz: string}}}, 'foo.bar', ['foo', 'bar'], AccessPattern<string>>
|
136
|
+
* = 'foo' | 'foo.bar.baz'
|
137
|
+
* ```
|
138
|
+
* @internal
|
139
|
+
*/
|
140
|
+
declare type AutoCompletePathImpl<T, PS extends PathString, PT extends PathTuple, C extends AccessPattern> = SuggestPaths<T, PT, C> | AutoCompletePathCheckConstraint<T, PS, PT, C>;
|
141
|
+
/**
|
142
|
+
* Type which given a type and a path string into it returns
|
143
|
+
* - its parent/predecessor path string.
|
144
|
+
* - the path string itself, if it exists within the type and matches
|
145
|
+
* the constraint type.
|
146
|
+
* - all its child/successor paths that point to a type which is either
|
147
|
+
* traversable or matches the constraint type.
|
148
|
+
* Also,
|
149
|
+
* - in case the path does not exist it returns all of the above for the last
|
150
|
+
* valid path.
|
151
|
+
* - in case the path is a union of paths it doesn't suggest any
|
152
|
+
* parent/predecessor and child/successor paths.
|
153
|
+
* Otherwise, the returned type may become to large, or it may accept paths
|
154
|
+
* which don't match the constraint type.
|
155
|
+
* @typeParam T - type which is indexed by the path
|
156
|
+
* @typeParam PS - the current path into the type as a string
|
157
|
+
* @typeParam C - constraint
|
158
|
+
* @example
|
159
|
+
* ```
|
160
|
+
* AutoCompletePath<{foo: {bar: string}}, 'foo', AccessPattern<string>>
|
161
|
+
* = 'foo.bar'
|
162
|
+
* AutoCompletePath<{foo: {bar: string}}, 'foo.ba', AccessPattern<string>>
|
163
|
+
* = 'foo' | 'foo.bar'
|
164
|
+
* AutoCompletePath<{foo: {bar: string}}, 'foo.bar', AccessPattern<string>>
|
165
|
+
* = 'foo' | 'foo.bar'
|
166
|
+
* AutoCompletePath<{foo: {bar: {baz: string}}}, 'foo.bar', AccessPattern<string>>
|
167
|
+
* = 'foo' | 'foo.bar.baz'
|
168
|
+
* ```
|
169
|
+
* @internal
|
170
|
+
*/
|
171
|
+
export declare type AutoCompletePath<T, PS extends PathString, C extends AccessPattern = AccessPattern> = IsAny<PS> extends true ? any : IsPathUnion<PS> extends false ? AutoCompletePathImpl<T, PS, SplitPathString<PS>, C> : PS extends any ? AutoCompletePathCheckConstraint<T, PS, SplitPathString<PS>, C> : never;
|
172
|
+
export {};
|
173
|
+
//# sourceMappingURL=autoCompletePath.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"autoCompletePath.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/autoCompletePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE/E;;;;;;;;;;GAUG;AACH,oBAAY,iBAAiB,CAAC,EAAE,SAAS,SAAS,IAAI,aAAa,CACjE,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CACtC,CAAC;AAEF;;;;;;GAMG;AACH,aAAK,qBAAqB,CACxB,EAAE,SAAS,SAAS,EACpB,GAAG,EACH,CAAC,SAAS,aAAa,IACrB,aAAa,CACf;IACE,GAAG,EAAE;IACL,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,WAAW,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;CACxE,CACF,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,oBAAY,iBAAiB,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AC,GACnB,KAAK,GACP,KAAK,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,aAAK,oBAAoB,CACvB,CAAC,EACD,EAAE,SAAS,UAAU,EACrB,EAAE,SAAS,SAAS,EACpB,CAAC,SAAS,aAAa,IACrB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,+BAA+B,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,oBAAY,gBAAgB,CAC1B,CAAC,EACD,EAAE,SAAS,UAAU,EACrB,CAAC,SAAS,aAAa,GAAG,aAAa,IACrC,KAAK,CAAC,EAAE,CAAC,SAAS,IAAI,GACtB,GAAG,GACH,WAAW,CAAC,EAAE,CAAC,SAAS,KAAK,GAC7B,oBAAoB,CAAC,CAAC,EAAE,EAAE,EAAE,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACnD,EAAE,SAAS,GAAG,GACd,+BAA+B,CAAC,CAAC,EAAE,EAAE,EAAE,eAAe,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC9D,KAAK,CAAC"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import { IsNever } from '../../utils';
|
2
|
+
import { Keys } from './keys';
|
3
|
+
import { KeyGetValue } from './pathGetValue';
|
4
|
+
import { AsPathTuple, PathTuple } from './pathTuple';
|
5
|
+
import { AsKey, Key } from './utils';
|
6
|
+
/**
|
7
|
+
* Type to check whether a key is present in a type.
|
8
|
+
* If a union of keys is passed, all keys have to be present in the type.
|
9
|
+
* @typeParam T - type which is introspected
|
10
|
+
* @typeParam K - key
|
11
|
+
* @example
|
12
|
+
* ```
|
13
|
+
* HasKey<{foo: string}, 'foo'> = true
|
14
|
+
* HasKey<{foo: string}, 'bar'> = false
|
15
|
+
* HasKey<{foo: string}, 'foo' | 'bar'> = false
|
16
|
+
* ```
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
export declare type HasKey<T, K extends Key> = IsNever<Exclude<K, Keys<T>>>;
|
20
|
+
/**
|
21
|
+
* Type to implement {@link ValidPathPrefix} tail recursively.
|
22
|
+
* @typeParam T - type which the path should be checked against
|
23
|
+
* @typeParam PT - path which should exist within the given type
|
24
|
+
* @typeParam VPT - accumulates the prefix of keys which have been
|
25
|
+
* confirmed to exist already
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
declare type ValidPathPrefixImpl<T, PT extends PathTuple, VPT extends PathTuple> = PT extends [infer K, ...infer R] ? HasKey<T, AsKey<K>> extends true ? ValidPathPrefixImpl<KeyGetValue<T, AsKey<K>>, AsPathTuple<R>, AsPathTuple<[...VPT, K]>> : VPT : VPT;
|
29
|
+
/**
|
30
|
+
* Type to find the longest path prefix which is still valid,
|
31
|
+
* i.e. exists within the given type.
|
32
|
+
* @typeParam T - type which the path should be checked against
|
33
|
+
* @typeParam PT - path which should exist within the given type
|
34
|
+
* @example
|
35
|
+
* ```
|
36
|
+
* ValidPathPrefix<{foo: {bar: string}}, ['foo', 'bar']> = ['foo', 'bar']
|
37
|
+
* ValidPathPrefix<{foo: {bar: string}}, ['foo', 'ba']> = ['foo']
|
38
|
+
* ```
|
39
|
+
* @internal
|
40
|
+
*/
|
41
|
+
export declare type ValidPathPrefix<T, PT extends PathTuple> = ValidPathPrefixImpl<T, PT, [
|
42
|
+
]>;
|
43
|
+
/**
|
44
|
+
* Type to check whether a path through a type exists.
|
45
|
+
* @typeParam T - type which the path should be checked against
|
46
|
+
* @typeParam PT - path which should exist within the given type
|
47
|
+
* @example
|
48
|
+
* ```
|
49
|
+
* HasPath<{foo: {bar: string}}, ['foo', 'bar']> = true
|
50
|
+
* HasPath<{foo: {bar: string}}, ['foo', 'ba']> = false
|
51
|
+
* ```
|
52
|
+
* @internal
|
53
|
+
*/
|
54
|
+
export declare type HasPath<T, PT extends PathTuple> = ValidPathPrefix<T, PT> extends PT ? true : false;
|
55
|
+
export {};
|
56
|
+
//# sourceMappingURL=hasPath.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"hasPath.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/hasPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,oBAAY,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,aAAK,mBAAmB,CACtB,CAAC,EACD,EAAE,SAAS,SAAS,EACpB,GAAG,SAAS,SAAS,IACnB,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAChC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAC9B,mBAAmB,CACjB,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EACxB,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CACzB,GACD,GAAG,GACL,GAAG,CAAC;AAER;;;;;;;;;;;GAWG;AACH,oBAAY,eAAe,CAAC,CAAC,EAAE,EAAE,SAAS,SAAS,IAAI,mBAAmB,CACxE,CAAC,EACD,EAAE,EACF;CAAE,CACH,CAAC;AAEF;;;;;;;;;;GAUG;AACH,oBAAY,OAAO,CAAC,CAAC,EAAE,EAAE,SAAS,SAAS,IAAI,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,GAC5E,IAAI,GACJ,KAAK,CAAC"}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import { IsAny, IsNever } from '../../utils';
|
2
|
+
import { KeyGetValue } from './pathGetValue';
|
3
|
+
import { KeySetValue } from './pathSetValue';
|
4
|
+
import { AccessPattern, ArrayKey, IsTuple, Key, ToKey, Traversable, UnionToIntersection } from './utils';
|
5
|
+
/**
|
6
|
+
* Type which given a tuple type returns its own keys, i.e. only its indices.
|
7
|
+
* @typeParam T - tuple type
|
8
|
+
* @example
|
9
|
+
* ```
|
10
|
+
* TupleKeys<[number, string]> = '0' | '1'
|
11
|
+
* ```
|
12
|
+
* @internal
|
13
|
+
*/
|
14
|
+
export declare type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
|
15
|
+
/**
|
16
|
+
* Type which extracts all numeric keys from an object.
|
17
|
+
* @typeParam T - type
|
18
|
+
* @example
|
19
|
+
* ```
|
20
|
+
* NumericObjectKeys<{0: string, '1': string, foo: string}> = '0' | '1'
|
21
|
+
* ```
|
22
|
+
* @internal
|
23
|
+
*/
|
24
|
+
declare type NumericObjectKeys<T extends Traversable> = ToKey<Extract<keyof T, ArrayKey | `${ArrayKey}`>>;
|
25
|
+
/**
|
26
|
+
* Type which extracts all numeric keys from an object, tuple, or array.
|
27
|
+
* If a union is passed, it evaluates to the overlapping numeric keys.
|
28
|
+
* @typeParam T - type
|
29
|
+
* @example
|
30
|
+
* ```
|
31
|
+
* NumericKeys<{0: string, '1': string, foo: string}> = '0' | '1'
|
32
|
+
* NumericKeys<number[]> = `${number}`
|
33
|
+
* NumericKeys<[string, number]> = '0' | '1'
|
34
|
+
* NumericKeys<{0: string, '1': string} | [number] | number[]> = '0'
|
35
|
+
* ```
|
36
|
+
* @internal
|
37
|
+
*/
|
38
|
+
export declare type NumericKeys<T extends Traversable> = UnionToIntersection<T extends ReadonlyArray<any> ? IsTuple<T> extends true ? [TupleKeys<T>] : [ToKey<ArrayKey>] : [NumericObjectKeys<T>]>[never];
|
39
|
+
/**
|
40
|
+
* Type which extracts all keys from an object.
|
41
|
+
* If a union is passed, it evaluates to the overlapping keys.
|
42
|
+
* @typeParam T - object type
|
43
|
+
* @example
|
44
|
+
* ```
|
45
|
+
* ObjectKeys<{foo: string, bar: string}, string> = 'foo' | 'bar'
|
46
|
+
* ObjectKeys<{foo: string, bar: number}, string> = 'foo'
|
47
|
+
* ```
|
48
|
+
* @internal
|
49
|
+
*/
|
50
|
+
export declare type ObjectKeys<T extends Traversable> = Exclude<ToKey<keyof T>, `${string}.${string}` | ''>;
|
51
|
+
/**
|
52
|
+
* Type to check whether a type's property matches the constraint type
|
53
|
+
* and return its key. Converts the key to a string.
|
54
|
+
* @typeParam T - type whose property should be checked
|
55
|
+
* @typeParam K - key of the property
|
56
|
+
* @typeParam C - constraint
|
57
|
+
* @example
|
58
|
+
* ```
|
59
|
+
* CheckKeyConstraint<{foo: string}, 'foo', AccessPattern<string>> = 'foo'
|
60
|
+
* CheckKeyConstraint<{foo: string}, 'foo', AccessPattern<number>> = never
|
61
|
+
* CheckKeyConstraint<string[], number, AccessPattern<string>> = `${number}`
|
62
|
+
* ```
|
63
|
+
* @internal
|
64
|
+
*/
|
65
|
+
export declare type CheckKeyConstraint<T, K extends Key, C extends AccessPattern> = K extends any ? AccessPattern<KeyGetValue<T, K>, KeySetValue<T, K>> extends C ? K : never : never;
|
66
|
+
/**
|
67
|
+
* Type which evaluates to true when the type is an array or tuple or is a union
|
68
|
+
* which contains an array or tuple.
|
69
|
+
* @typeParam T - type
|
70
|
+
* @example
|
71
|
+
* ```
|
72
|
+
* ContainsIndexable<{foo: string}> = false
|
73
|
+
* ContainsIndexable<{foo: string} | number[]> = true
|
74
|
+
* ```
|
75
|
+
* @internal
|
76
|
+
*/
|
77
|
+
export declare type ContainsIndexable<T> = IsNever<Extract<T, ReadonlyArray<any>>> extends true ? false : true;
|
78
|
+
/**
|
79
|
+
* Type to implement {@link Keys} for non-nullable values.
|
80
|
+
* @typeParam T - non-nullable type whose property should be checked
|
81
|
+
* @internal
|
82
|
+
*/
|
83
|
+
declare type KeysImpl<T> = [T] extends [Traversable] ? ContainsIndexable<T> extends true ? NumericKeys<T> : ObjectKeys<T> : never;
|
84
|
+
/**
|
85
|
+
* Type to find all properties of a type that match the constraint type
|
86
|
+
* and return their keys.
|
87
|
+
* If a union is passed, it evaluates to the overlapping keys.
|
88
|
+
* @typeParam T - type whose property should be checked
|
89
|
+
* @typeParam C - constraint
|
90
|
+
* @example
|
91
|
+
* ```
|
92
|
+
* Keys<{foo: string, bar: string}, AccessPattern<string>> = 'foo' | 'bar'
|
93
|
+
* Keys<{foo?: string, bar?: string}> = 'foo' | 'bar'
|
94
|
+
* Keys<{foo: string, bar: number}, AccessPattern<string>> = 'foo'
|
95
|
+
* Keys<[string, number], string> = '0'
|
96
|
+
* Keys<string[], AccessPattern<string>> = `${number}`
|
97
|
+
* Keys<{0: string, '1': string} | [number] | number[]> = '0'
|
98
|
+
* ```
|
99
|
+
* @internal
|
100
|
+
*/
|
101
|
+
export declare type Keys<T, C extends AccessPattern = AccessPattern> = IsAny<T> extends true ? Key : IsNever<T> extends true ? Key : IsNever<NonNullable<T>> extends true ? never : CheckKeyConstraint<T, KeysImpl<NonNullable<T>>, C>;
|
102
|
+
export {};
|
103
|
+
//# sourceMappingURL=keys.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,aAAa,EACb,QAAQ,EACR,OAAO,EACP,GAAG,EACH,KAAK,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,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAC/B,SAAS,IAAI,GACV,KAAK,GACL,IAAI,CAAC;AAET;;;;GAIG;AACH,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,GACxC,iBAAiB,CAAC,CAAC,CAAC,SAAS,IAAI,GAC/B,WAAW,CAAC,CAAC,CAAC,GACd,UAAU,CAAC,CAAC,CAAC,GACf,KAAK,CAAC;AAEV;;;;;;;;;;;;;;;;GAgBG;AACH,oBAAY,IAAI,CACd,CAAC,EACD,CAAC,SAAS,aAAa,GAAG,aAAa,IACrC,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,GACrB,GAAG,GACH,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GACvB,GAAG,GACH,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACpC,KAAK,GACL,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { IsAny, IsNever } from '../../utils';
|
2
|
+
import { AsPathTuple, PathTuple } from './pathTuple';
|
3
|
+
import { ArrayKey, AsKey, IsTuple, Key, MapKeys } from './utils';
|
4
|
+
/**
|
5
|
+
* Type to access a type by a key.
|
6
|
+
* - Returns undefined if it can't be indexed by that key.
|
7
|
+
* - Returns null if the type is null.
|
8
|
+
* - Returns undefined if the type is not traversable.
|
9
|
+
* @typeParam T - type which is indexed by the key
|
10
|
+
* @typeParam K - key into the type
|
11
|
+
* ```
|
12
|
+
* TryGet<{foo: string}, 'foo'> = string
|
13
|
+
* TryGet<{foo: string}, 'bar'> = undefined
|
14
|
+
* TryGet<null, 'foo'> = null
|
15
|
+
* TryGet<string, 'foo'> = undefined
|
16
|
+
* ```
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
declare type TryGet<T, K> = K extends keyof T ? T[K] : T extends null | undefined ? T : unknown;
|
20
|
+
/**
|
21
|
+
* Type to access an array type by a key.
|
22
|
+
* @typeParam T - type which is indexed by the key
|
23
|
+
* @typeParam K - key into the type
|
24
|
+
* ```
|
25
|
+
* TryGetArray<string[], '0'> = string
|
26
|
+
* TryGetArray<string[], 'foo'> = undefined
|
27
|
+
* ```
|
28
|
+
* @internal
|
29
|
+
*/
|
30
|
+
declare type TryGetArray<T extends ReadonlyArray<any>, K extends Key> = K extends `${ArrayKey}` ? T[number] : TryGet<T, K>;
|
31
|
+
/**
|
32
|
+
* Type to evaluate the type which the given key points to.
|
33
|
+
* - If either T or K is union, it will evaluate to the union of the types at
|
34
|
+
* the given key(s).
|
35
|
+
* - If T can be null or undefined, the resulting type will also include null
|
36
|
+
* or undefined.
|
37
|
+
* - If a key doesn't exist, or may be optional, the resulting type will
|
38
|
+
* include undefined.
|
39
|
+
* @typeParam T - type which is indexed by the key
|
40
|
+
* @typeParam K - key into the type
|
41
|
+
* @example
|
42
|
+
* ```
|
43
|
+
* KeyGetValue<{foo: string}, 'foo'> = string
|
44
|
+
* KeyGetValue<{foo: string, bar: number}, 'foo' | 'bar'> = string | number
|
45
|
+
* KeyGetValue<{foo: string} | {foo: number}, 'foo'> = string | number
|
46
|
+
* KeyGetValue<null | {foo: string}, 'foo'> = null | string
|
47
|
+
* KeyGetValue<{bar: string}, 'foo'> = undefined
|
48
|
+
* KeyGetValue<{foo?: string}, 'foo'> = undefined | string
|
49
|
+
* ```
|
50
|
+
* @internal
|
51
|
+
*/
|
52
|
+
export declare type KeyGetValue<T, K extends Key> = IsNever<K> extends true ? unknown : T extends ReadonlyArray<any> ? IsTuple<T> extends true ? TryGet<T, K> : TryGetArray<T, K> : TryGet<MapKeys<T>, K>;
|
53
|
+
/**
|
54
|
+
* Type to evaluate the type which the given path points to.
|
55
|
+
* - If either T or PT is union, it will evaluate to the union of the types at
|
56
|
+
* the given path(s).
|
57
|
+
* - If T can be null or undefined, the resulting type will also include null
|
58
|
+
* or undefined.
|
59
|
+
* - If a path doesn't exist, or may be optional, the resulting type will
|
60
|
+
* include undefined.
|
61
|
+
* @typeParam T - deeply nested type which is indexed by the path
|
62
|
+
* @typeParam PT - path into the deeply nested type
|
63
|
+
* @example
|
64
|
+
* ```
|
65
|
+
* PathGetValue<{foo: {bar: string}}, ['foo', 'bar']> = string
|
66
|
+
* PathGetValue<{foo: string, bar: number}, ['foo'] | ['bar']> = string | number
|
67
|
+
* PathGetValue<{foo: string} | {foo: number}, ['foo']> = string | number
|
68
|
+
* PathGetValue<null | {foo: string}, ['foo']> = null | string
|
69
|
+
* PathGetValue<{bar: string}, ['foo']> = undefined
|
70
|
+
* PathGetValue<{foo?: string}, ['foo']> = undefined | string
|
71
|
+
* ```
|
72
|
+
* @internal
|
73
|
+
*/
|
74
|
+
export declare type PathGetValue<T, PT extends PathTuple> = IsAny<PT> extends true ? any : IsNever<PT> extends true ? unknown : PT extends [infer K, ...infer R] ? PathGetValue<KeyGetValue<T, AsKey<K>>, AsPathTuple<R>> : T;
|
75
|
+
export {};
|
76
|
+
//# sourceMappingURL=pathGetValue.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pathGetValue.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/pathGetValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,aAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GACjC,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,SAAS,IAAI,GAAG,SAAS,GAC1B,CAAC,GACD,OAAO,C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