Skip to content

[feature] .toEqualUnorderedTypeOf #24

@gomain

Description

@gomain

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

No one assigned

    Labels

    New featureNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions