-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix #1299: add support for icu macro in typescript #1310
Conversation
ts4.1/icu.d.ts
Outdated
declare module 'react-i18next/icu.macro' { | ||
type Namespace = import('.').Namespace; | ||
type DefaultNamespace = import('.').DefaultNamespace; | ||
type Resources = import('.').Resources; | ||
type TFuncKey<N extends Namespace = DefaultNamespace, T = Resources> = import('.').TFuncKey<N, T>; | ||
type i18n = import('i18next').i18n; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything inside the module will be exported (even without the export
keyword), I don't think we have an i18n
under react-i18next
. If you don't want to re-export all these types, you should import them outside the module.
declare module 'react-i18next/icu.macro' { | |
type Namespace = import('.').Namespace; | |
type DefaultNamespace = import('.').DefaultNamespace; | |
type Resources = import('.').Resources; | |
type TFuncKey<N extends Namespace = DefaultNamespace, T = Resources> = import('.').TFuncKey<N, T>; | |
type i18n = import('i18next').i18n; | |
import {Namespace, DefaultNamespace, Resources, TFuncKey, TransProps} from '.'; | |
import {i18n} from 'i18next'; | |
declare module 'react-i18next/icu.macro' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I did it this way, the types stopped working in VS Code, and it also failed to type them at all (they became any
). Can you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can add the export again if you want
ts4.1/icu.d.ts
Outdated
K extends TFuncKey<N> extends infer A ? A : never, | ||
N extends Namespace = DefaultNamespace | ||
> { | ||
children?: never; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can simply remove children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the intent here was to prevent children. In other words, typescript will error if you pass children in, as a way of signaling "children will be ignored"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will happen for Select
component only 🤔 , because you're intersecting its props with SelectSubProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, I'll add it to PluralProps to solve that oversight
ts4.1/icu.d.ts
Outdated
type TFuncKey<N extends Namespace = DefaultNamespace, T = Resources> = import('.').TFuncKey<N, T>; | ||
type i18n = import('i18next').i18n; | ||
|
||
export interface PluralSubProps< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned above all types inside the module will be exported so we don't need the export
keyword
ts4.1/icu.d.ts
Outdated
export function Trans< | ||
K extends TFuncKey<N> extends infer A ? A : never, | ||
N extends Namespace = DefaultNamespace, | ||
E extends Element = HTMLDivElement | ||
>(props: import('.').TransProps<K, N, E>): React.ReactElement; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can re-export the Trans
function, but it needs to be done outside the module.
export function Trans< | |
K extends TFuncKey<N> extends infer A ? A : never, | |
N extends Namespace = DefaultNamespace, | |
E extends Element = HTMLDivElement | |
>(props: import('.').TransProps<K, N, E>): React.ReactElement; | |
} | |
} | |
export { Trans }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!! 🎉 🙌
awesome! I'm going to put up the other PR idea in a draft PR. I will rebase it on master once this is merged, so I can add the typescript types for it too. Nice doing bidness wit you :) |
Checklist
npm run test