-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
New featureNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
I have a use case where the order of items in the construction of a tuple type is non-deterministic.
To test I currently do:
const tuple = expectTypeOf<TupleType>();
tuple.toMatchTypeOf<[any, any, any]>(); // has length 3
tuple.items.exclude<A | B>().toEqualTypeOf<C>(); // one of the items is C
tuple.items.exclude<A | C>().toEqualTypeOf<B>(); // one of the items is B
tuple.items.exclude<B | C>().toEqualTypeOf<A>(); // one of the items is A
But this only works when tuple items are indeed not union types. There is no way to test if one of the items type is a certain union type.
I propose a .toEqualUnorderedTypeOf
:
expectTypeOf<TestType>().toEqualUnorderedTypeOf<[A, B, A]>();
/* any of these would pass, and fail otherwise
* [A, B, A]
* [B, A, A]
* [A, A, B]
*/
Other matchers/combinators along this line are
.toContainTypeOf
// passes if at least one item has equal type.toContainItemsTypeOf
// passes if tuple items is a superset of provided tuple.excludeItem
// returns tuple with items of equal type removed, or fail if not found.excludeItems
// returns tuple minus (in set sense) the provided tuple, or fail if can't
Metadata
Metadata
Assignees
Labels
New featureNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed