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

HOCs need to be explicitly typed #562

Closed
nmenke opened this issue Oct 22, 2018 · 3 comments
Closed

HOCs need to be explicitly typed #562

nmenke opened this issue Oct 22, 2018 · 3 comments

Comments

@nmenke
Copy link

nmenke commented Oct 22, 2018

Hi,

i have updated to the newest version of react-i18next today. I have noticed that the repository now contains typings. So for example the following definition:

export function withNamespaces(
  namespace?: string,
  options?: WithNamespacesOptions,
): <P extends object>(
  component: React.ComponentType<P & WithNamespaces>,
) => React.ComponentType<P>;

With this definition i need to say withNamespaces("default")<Props>(component). Otherwise the compiler complains for missing Props like tReady.

type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type Subtract<T, K> = Omit<T, keyof K>;

export function withNamespaces(
  namespace?: string,
  options?: WithNamespacesOptions,
): <P extends WithNamespaces>(
  component: React.ComponentType<P>,
) => React.ComponentType<Subtract<P, WithNamespaces>>;

This definition removes those types supplied by the HOC and you can use following statement: withNamespaces("default")(component) without compiler errors. It would be great if those typings would be used for every HOC.

@schettino
Copy link
Collaborator

PR coming. @jamuhl want to patch the changes right away or give it sometime to see if something else comes up in this initial phase and then release the possible changes all at once?

@jamuhl
Copy link
Member

jamuhl commented Oct 22, 2018

@schettino i added you as contributor with write access - feel free to merge in changes as needed - and ping me if there is a state we should publish again...

@schettino
Copy link
Collaborator

@jamuhl sounds good, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants