inferred-types 0.30.0 → 0.30.2
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/index.d.ts
CHANGED
|
@@ -981,7 +981,7 @@ declare type MapFn<I, O, C extends FinalizedMapConfig<OptRequired, MapCardinalit
|
|
|
981
981
|
* const mappedOver = inputs.map(m);
|
|
982
982
|
* ```
|
|
983
983
|
*/
|
|
984
|
-
declare type Mapper<I, O, C extends FinalizedMapConfig<OptRequired, MapCardinalityIllustrated, OptRequired>> = {
|
|
984
|
+
declare type Mapper<I = unknown, O = unknown, C extends FinalizedMapConfig<OptRequired, MapCardinalityIllustrated, OptRequired> = FinalizedMapConfig<OptRequired, MapCardinalityIllustrated, OptRequired>> = {
|
|
985
985
|
input: MapIR<C>;
|
|
986
986
|
output: MapOR<C>;
|
|
987
987
|
cardinality: MapCard<C>;
|
|
@@ -989,6 +989,24 @@ declare type Mapper<I, O, C extends FinalizedMapConfig<OptRequired, MapCardinali
|
|
|
989
989
|
inputType: I;
|
|
990
990
|
outputType: O;
|
|
991
991
|
} & MapFn<I, O, C>;
|
|
992
|
+
/**
|
|
993
|
+
* **MapInputFrom**
|
|
994
|
+
*
|
|
995
|
+
* Type utility which extracts the `I` type from a fully configured `Mapper`
|
|
996
|
+
*/
|
|
997
|
+
declare type MapInputFrom<T extends Mapper> = T extends Mapper<infer I> ? I : never;
|
|
998
|
+
/**
|
|
999
|
+
* **MapOutputFrom**
|
|
1000
|
+
*
|
|
1001
|
+
* Type utility which extracts the output [`O`] type from a fully configured `Mapper`
|
|
1002
|
+
*/
|
|
1003
|
+
declare type MapOutputFrom<T extends Mapper> = T extends Mapper<any, infer O> ? O : never;
|
|
1004
|
+
/**
|
|
1005
|
+
* **MapCardinalityFrom**
|
|
1006
|
+
*
|
|
1007
|
+
* Type utility which extracts _cardinality_ of a `Mapper`'s inputs to outputs
|
|
1008
|
+
*/
|
|
1009
|
+
declare type MapCardinalityFrom<T extends Mapper> = T extends Mapper<any, any, infer C> ? C extends FinalizedMapConfig<OptRequired, infer Cardinality, OptRequired> ? Cardinality : never : never;
|
|
992
1010
|
|
|
993
1011
|
/**
|
|
994
1012
|
* Given a dictionary of type `<T>`, this utility function will
|
|
@@ -2279,4 +2297,4 @@ interface IFluentConfigurator<C> {
|
|
|
2279
2297
|
*/
|
|
2280
2298
|
declare function FluentConfigurator<I>(initial?: I): IFluentConfigurator<{}>;
|
|
2281
2299
|
|
|
2282
|
-
export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AsArray, AsFinalizedConfig, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, Cardinality, Cardinality0, Cardinality1, CardinalityExplicit, CardinalityFilter0, CardinalityFilter1, CardinalityIn, CardinalityInput, CardinalityNode, CardinalityOut, CardinalityTuple, ClosingBracket, Condition, ConditionFilter, Configurator, ConfiguredMap, Constructor, DEFAULT_MANY_TO_ONE_MAPPING, DEFAULT_ONE_TO_MANY_MAPPING, DEFAULT_ONE_TO_ONE_MAPPING, DashToSnake, DashUppercase, Dasherize, DecomposeMapConfig, DefaultManyToOneMapping, DefaultOneToManyMapping, DefaultOneToOneMapping, DefinePropertiesApi, DictArrApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, Extends, ExtendsClause, ExtendsNarrowlyClause, FilterContains, FilterDefn, FilterEnds, FilterEquals, FilterFn, FilterGreaterThan, FilterIs, FilterLessThan, FilterNotEqual, FilterStarts, FinalReturn, FinalizedMapConfig, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfBooleanLiteral, IfExtends, IfExtendsThen, IfLiteral, IfNumericLiteral, IfObject, IfOptionalLiteral, IfScalar, IfStringLiteral, Include, Includes, IntersectingKeys, IsArray, IsBoolean, IsBooleanLiteral, IsCapitalized, IsFalse, IsFunction, IsLiteral, IsNumericLiteral, IsObject, IsOptionalLiteral, IsScalar, IsString, IsStringLiteral, IsTrue, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LogicFunction, LogicalCombinator, LowerAllCaps, LowerAlpha, ManyToMany, ManyToOne, ManyToZero, MapCard, MapCardinality, MapCardinalityIllustrated, MapConfig, MapFn, MapFnInput, MapFnOutput, MapIR, MapInput, MapOR, MapOutput, MapTo, Mapper, MapperApi, MaybeFalse, MaybeTrue, Model, Mutable, MutableProps, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, NotFilter, Numeric, NumericFilter, NumericKeys, NumericString, ObjectType, OneToMany, OneToOne, OneToZero, Opaque, OpeningBracket, OptRequired, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimplifyObject, SnakeCase, SpecialCharacters, StringDelimiter, StringFilter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefault, TypeDefinition, TypeGuard, TypeOptions, UndefinedArrayIsUnknown, UndefinedTreatment, UndefinedValue, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, Uniqueness, UnwrapNot, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, Widen, WithNumericKeys, WithStringKeys, WithValue, ZeroToMany, ZeroToOne, ZeroToZero, ZipCode, and, api, arrayToKeyLookup, arrayToObject, asArray, condition, createFnWithProps, createMutationFunction, defineProperties, defineType, dictArr, dictToKv, dictionaryTransform, entries, filter, filterDictArray, fnWithProps, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isNotFilter, isNull, isNumber, isNumericFilter, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, literal, mapTo, mapToDict, mapToFn, mapValues, nameLiteral, not, or, randomString, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, withValue };
|
|
2300
|
+
export { AllCaps, Alpha, AlphaNumeric, Api, ApiFunction, ApiValue, AppendToDictionary, AppendToObject, ArrConcat, Array$1 as Array, ArrayConverter, AsArray, AsFinalizedConfig, AssertExtends, Bracket, Break, CamelCase, CapitalizeWords, Cardinality, Cardinality0, Cardinality1, CardinalityExplicit, CardinalityFilter0, CardinalityFilter1, CardinalityIn, CardinalityInput, CardinalityNode, CardinalityOut, CardinalityTuple, ClosingBracket, Condition, ConditionFilter, Configurator, ConfiguredMap, Constructor, DEFAULT_MANY_TO_ONE_MAPPING, DEFAULT_ONE_TO_MANY_MAPPING, DEFAULT_ONE_TO_ONE_MAPPING, DashToSnake, DashUppercase, Dasherize, DecomposeMapConfig, DefaultManyToOneMapping, DefaultOneToManyMapping, DefaultOneToOneMapping, DefinePropertiesApi, DictArrApi, DictArray, DictArrayFilterCallback, DictArrayKv, DictChangeValue, DictFromKv, DictKvTuple, DictPartialApplication, DictPrependWithFn, DictReturnValues, DynamicRule, DynamicRuleSet, Email, EnumValues, ExpandRecursively, ExpectExtends, ExplicitFunction, Extends, ExtendsClause, ExtendsNarrowlyClause, FilterContains, FilterDefn, FilterEnds, FilterEquals, FilterFn, FilterGreaterThan, FilterIs, FilterLessThan, FilterNotEqual, FilterStarts, FinalReturn, FinalizedMapConfig, First, FirstKey, FirstKeyValue, FirstOfEach, FluentConfigurator, FluentFunction, FromDictArray, FunctionType, GeneralDictionary, Get, HasUppercase, IConfigurator, IFluentConfigurator, If, IfBooleanLiteral, IfExtends, IfExtendsThen, IfLiteral, IfNumericLiteral, IfObject, IfOptionalLiteral, IfScalar, IfStringLiteral, Include, Includes, IntersectingKeys, IsArray, IsBoolean, IsBooleanLiteral, IsCapitalized, IsFalse, IsFunction, IsLiteral, IsNumericLiteral, IsObject, IsOptionalLiteral, IsScalar, IsString, IsStringLiteral, IsTrue, KebabCase, KeyValue, KeyedRecord, Keys, KeysWithValue, KvFrom, KvTuple, LastInUnion, LeftWhitespace, Length, LogicFunction, LogicalCombinator, LowerAllCaps, LowerAlpha, ManyToMany, ManyToOne, ManyToZero, MapCard, MapCardinality, MapCardinalityFrom, MapCardinalityIllustrated, MapConfig, MapFn, MapFnInput, MapFnOutput, MapIR, MapInput, MapInputFrom, MapOR, MapOutput, MapOutputFrom, MapTo, Mapper, MapperApi, MaybeFalse, MaybeTrue, Model, Mutable, MutableProps, MutationFunction, MutationIdentity, Narrowable, NonAlpha, NonNumericKeys, NonStringKeys, Not, NotFilter, Numeric, NumericFilter, NumericKeys, NumericString, ObjectType, OneToMany, OneToOne, OneToZero, Opaque, OpeningBracket, OptRequired, OptionalKeys, OptionalProps, Parenthesis, PascalCase, Pluralize, PrivateKey, PrivateKeys, PublicKeys, Punctuation, PureFluentApi, Replace, RequireProps, RequiredKeys, RequiredProps, Retain, RightWhitespace, RuleDefinition, RuntimeProp, RuntimeType, SameKeys, SecondOfEach, SimplifyObject, SnakeCase, SpecialCharacters, StringDelimiter, StringFilter, StringKeys, StringLength, ToFluent, Transformer, Trim, TrimLeft, TrimRight, TupleToUnion, Type, TypeApi, TypeCondition, TypeDefault, TypeDefinition, TypeGuard, TypeOptions, UndefinedArrayIsUnknown, UndefinedTreatment, UndefinedValue, UnionToIntersection, UnionToTuple, UniqueDictionary, UniqueForProp, Uniqueness, UnwrapNot, UpperAlpha, ValueTuple, ValueTypeFunc, ValueTypes, Where, WhereNot, Whitespace, Widen, WithNumericKeys, WithStringKeys, WithValue, ZeroToMany, ZeroToOne, ZeroToZero, ZipCode, and, api, arrayToKeyLookup, arrayToObject, asArray, condition, createFnWithProps, createMutationFunction, defineProperties, defineType, dictArr, dictToKv, dictionaryTransform, entries, filter, filterDictArray, fnWithProps, groupBy, idLiteral, idTypeGuard, identity, ifTypeOf, isArray, isBoolean, isFalse, isFunction, isNotFilter, isNull, isNumber, isNumericFilter, isObject, isString, isSymbol, isTrue, isType, isUndefined, keys, kindLiteral, kv, kvToDict, literal, mapTo, mapToDict, mapToFn, mapValues, nameLiteral, not, or, randomString, readonlyFnWithProps, ruleSet, strArrayToDict, type, typeApi, uuid, valueTypes, withValue };
|
package/package.json
CHANGED
|
@@ -374,9 +374,13 @@ export type MapFn<
|
|
|
374
374
|
* ```
|
|
375
375
|
*/
|
|
376
376
|
export type Mapper<
|
|
377
|
-
I,
|
|
378
|
-
O,
|
|
379
|
-
C extends FinalizedMapConfig<
|
|
377
|
+
I = unknown,
|
|
378
|
+
O = unknown,
|
|
379
|
+
C extends FinalizedMapConfig<
|
|
380
|
+
OptRequired,
|
|
381
|
+
MapCardinalityIllustrated,
|
|
382
|
+
OptRequired
|
|
383
|
+
> = FinalizedMapConfig<OptRequired, MapCardinalityIllustrated, OptRequired>
|
|
380
384
|
> = {
|
|
381
385
|
input: MapIR<C>;
|
|
382
386
|
output: MapOR<C>;
|
|
@@ -385,3 +389,28 @@ export type Mapper<
|
|
|
385
389
|
inputType: I;
|
|
386
390
|
outputType: O;
|
|
387
391
|
} & MapFn<I, O, C>;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* **MapInputFrom**
|
|
395
|
+
*
|
|
396
|
+
* Type utility which extracts the `I` type from a fully configured `Mapper`
|
|
397
|
+
*/
|
|
398
|
+
export type MapInputFrom<T extends Mapper> = T extends Mapper<infer I> ? I : never;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* **MapOutputFrom**
|
|
402
|
+
*
|
|
403
|
+
* Type utility which extracts the output [`O`] type from a fully configured `Mapper`
|
|
404
|
+
*/
|
|
405
|
+
export type MapOutputFrom<T extends Mapper> = T extends Mapper<any, infer O> ? O : never;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* **MapCardinalityFrom**
|
|
409
|
+
*
|
|
410
|
+
* Type utility which extracts _cardinality_ of a `Mapper`'s inputs to outputs
|
|
411
|
+
*/
|
|
412
|
+
export type MapCardinalityFrom<T extends Mapper> = T extends Mapper<any, any, infer C>
|
|
413
|
+
? C extends FinalizedMapConfig<OptRequired, infer Cardinality, OptRequired>
|
|
414
|
+
? Cardinality
|
|
415
|
+
: never
|
|
416
|
+
: never;
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
MapConfig,
|
|
8
8
|
ConfiguredMap,
|
|
9
9
|
Mapper,
|
|
10
|
+
MapInputFrom,
|
|
11
|
+
MapCardinalityFrom,
|
|
10
12
|
} from "src/types/dictionary";
|
|
11
13
|
import { describe, expect, it } from "vitest";
|
|
12
14
|
import type { Expect, Equal } from "@type-challenges/utils";
|
|
@@ -257,6 +259,8 @@ describe("mapTo() utility function", () => {
|
|
|
257
259
|
it("Mapper<I,O,C>", () => {
|
|
258
260
|
const m0 = mapTo.oneToOne();
|
|
259
261
|
const m1 = m0.map<I, I>((i) => i);
|
|
262
|
+
type M1 = MapInputFrom<typeof m1>;
|
|
263
|
+
type MC = MapCardinalityFrom<typeof m1>;
|
|
260
264
|
|
|
261
265
|
expect(m1.input).toBe("req");
|
|
262
266
|
expect(m1.output).toBe("req");
|
|
@@ -265,9 +269,11 @@ describe("mapTo() utility function", () => {
|
|
|
265
269
|
|
|
266
270
|
type cases = [
|
|
267
271
|
Expect<Equal<typeof m1["inputType"], I>>, //
|
|
268
|
-
Expect<Equal<typeof m1["outputType"], I
|
|
272
|
+
Expect<Equal<typeof m1["outputType"], I>>, //
|
|
273
|
+
Expect<Equal<M1, I>>, //
|
|
274
|
+
Expect<Equal<MC, "I -> O">> //
|
|
269
275
|
];
|
|
270
|
-
const cases: cases = [true, true];
|
|
276
|
+
const cases: cases = [true, true, true, true];
|
|
271
277
|
});
|
|
272
278
|
|
|
273
279
|
it("M:1 conversion", () => {
|