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

Stronger typed Repository wrapper #262

Open
tjsb opened this issue Feb 10, 2023 · 0 comments
Open

Stronger typed Repository wrapper #262

tjsb opened this issue Feb 10, 2023 · 0 comments

Comments

@tjsb
Copy link

tjsb commented Feb 10, 2023

Have been playing around with this. Something that might be of use which I am doing is wrapping the Repository class in a stronger typed wrapper - just so that you get better IDE support etc: Here I'm using a custom cast function - but you can achieve the same with return types eg Promise<T> etc

const cast = <T>(x: T) => x;

export class TypedRepository extends Repository {
  async get<T>(id: unknown) {
    const entity = await super.get(id);

    return cast<T>(entity);
  }

  async commit<T>(
    entity: T,
    options?: {
      forceSnapshot: boolean;
    },
  ) {
    const e = await super.commit(entity, options);

    return cast<T>(e);
  }
}

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