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

Update react-i18next types for 8.0.7 #29807

Closed
wants to merge 4 commits into from

Conversation

Jessidhia
Copy link
Member

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
    • npm test is failing on an unrelated package, some package.json lint?
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).
    • some of the lints were there before

Select one of these and delete the others:

If changing an existing definition:

Fixes #29480.


export interface ReactI18NextOptions {
wait?: boolean;
withRef?: boolean;
bindI18n?: string;
bindStore?: string;
/**
* @deprecated This option is now ignored and the function name is always `t`
*/
translateFuncName?: string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change its type to 't' or just remove it altogether. I only kept it because it still technically exists in the return from getDefaults().


export type ContextInferableComponentEnhancerWithProps =
<P extends { [key: string]: any }>(component: React.ComponentClass<P> | React.StatelessComponent<P>) =>
React.ComponentClass<Omit<P, keyof ReactI18nContext> & React.ClassAttributes<never>>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been adding React.ClassAttributes<never> to the HOC to help avoid accidentally saving a ref to the HOC instead of the actually wrapped component. The getWrappedInstance() API is gone from react-i18next.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried using React.ClassAttributes<React.ComponentClass> but that was not causing an expected type error on tests.


type ComponentPropsWithInnerRef<T extends React.ComponentType<any>> =
(T extends React.ComponentClass<infer P>
? P & { innerRef?: React.Ref<InstanceType<T>> }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See i18next/react-i18next#534

This only works with withNamespaces for now.

: T extends React.SFC<infer P>
? P
: {}
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type ComponentProps<T extends React.ComponentType<any>> =
  T extends React.ComponentType<infer P> ? P : {}

sounds like something that could be useful in react.d.ts itself, at least until infer is allowed in places other than conditional type conditions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The any is required by the way; the type argument is not contravariant so it would not allow a component to receive more props than are enumerated.

@Jessidhia
Copy link
Member Author

Jessidhia commented Oct 17, 2018

Should I fix the lints on the v7 branch?

Also, what should be done about the helper types that are not exported (and were not exported to begin with); use export {} or export them too even though they're not library types?

I also kinda ended up abusing CI, but running npm test locally produces:

Error: In .../DefinitelyTyped/types/react-native-svg-charts/package.json: Dependency react-native-svg not in whitelist.
If you are depending on another `@types` package, do *not* add it to a `package.json`. Path mapping should make the import work.
If this is an external library that provides typings,  please make a pull request to types-publisher adding it to `dependenciesWhitelist.txt`.

Which specific package errors varies.

@typescript-bot
Copy link
Contributor

typescript-bot commented Oct 17, 2018

@Kovensky Thank you for submitting this PR!

Because this is a new definition, a DefinitelyTyped maintainer will be reviewing this PR in the next few days once the Travis CI build passes.

In the meantime, if the build fails or a merge conflict occurs, I'll let you know. Have a nice day!

@typescript-bot typescript-bot added New Definition This PR creates a new definition package. The Travis CI build failed labels Oct 17, 2018
@typescript-bot
Copy link
Contributor

typescript-bot commented Oct 17, 2018

@Kovensky The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!


export interface WithNamespaces {
<TNamespace extends string>
(namespaces: TNamespace | TNamespace[] | undefined, options?: Omit<TranslateOptions, "translateFuncName">):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing this typing on a local project, Typescript was telling me that withNamespaces was expecting 1 or 2 arguments. Considering withNamespaces loads the defaultNS defined in i18next if nothing is passed through it, would it be better to make namespaces optional here instead of defining undefined?

@Jessidhia
Copy link
Member Author

Jessidhia commented Oct 17, 2018 via email

beheh added a commit to beheh/DefinitelyTyped that referenced this pull request Oct 22, 2018
These have been released upstream as of react-i18next 8.1.0.
See i18next/react-i18next#557.

Closes DefinitelyTyped#29408
Closes DefinitelyTyped#29480
Closes DefinitelyTyped#29685
Closes DefinitelyTyped#29807
beheh added a commit to beheh/DefinitelyTyped that referenced this pull request Oct 22, 2018
The upstream library now ships it's own as of react-i18next 8.1.0.
See i18next/react-i18next#557.

Closes DefinitelyTyped#29408
Closes DefinitelyTyped#29480
Closes DefinitelyTyped#29685
Closes DefinitelyTyped#29807
@beheh
Copy link
Contributor

beheh commented Oct 22, 2018

This PR is probably obsolete, as typings have now been included upstream: i18next/react-i18next#557 and released in 8.1.0.

@Jessidhia
Copy link
Member Author

Jessidhia commented Oct 23, 2018

Unfortunately the upstream typings are quite lacking compared to the typings here... anys or things that are effectively any where generics should be, for example.

Guess it'll need some patching.

@beheh
Copy link
Contributor

beheh commented Oct 23, 2018

Right - I think in that case we should just try to get these into upstream using PRs there. The maintainer there has shown interest in accepting changes fast and I'm already seeing a bunch of PRs on that repo.

@typescript-bot
Copy link
Contributor

@Kovensky I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Oct 24, 2018
@typescript-bot
Copy link
Contributor

@Kovensky To keep things tidy, we have to close PRs that aren't mergeable but don't have activity from their author. No worries, though - please open a new PR if you'd like to continue with this change. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Abandoned This PR had no activity for a long time, and is considered abandoned New Definition This PR creates a new definition package.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants