Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper method to do includes against reacted arrays #884

Open
stephenh opened this issue Nov 19, 2023 · 0 comments
Open

Add helper method to do includes against reacted arrays #884

stephenh opened this issue Nov 19, 2023 · 0 comments

Comments

@stephenh
Copy link
Collaborator

stephenh commented Nov 19, 2023

Currently if you've got a list of reacted entities, and want to do an reactedEntities.includes(someOtherEntity), you basically always get a type error and have to as any around it.

  function asEntities<T extends Entity>(
    entities: ReadonlyArray<Omit<Reacted<T, any>, "fullNonReactiveAccess">>,
  ): readonly T[] {
    return entities as unknown as T[];
  }

  describe("types", () => {
    it("can do includes checks with entities", () => {
      // Given an array of reacted entities
      const books: Reacted<Book, "comments">[] = [];
      // And a regular book
      const b: Book = null!;
      // Then we can do includes checks
      expect(asEntities(books).includes(b)).toBe(false);
    });

    it("can do includes checks with other reactions", () => {
      // Given an array of reacted entities
      const books: Reacted<Book, "comments">[] = [];
      // And a different reacted book
      const b: Reacted<Book, {}> = null!;
      // Then we can do includes checks
      expect(asEntities(books).includes(b)).toBe(false);
      // And we can't do it with an author
      const a: Reacted<Author, {}> = null!;
      expect(asEntities(books).includes(a)).toBe(false);
    });
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant