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

All i18n type definitions are of type 'any' #26022

Closed
EvanShaw opened this issue Oct 12, 2020 · 4 comments
Closed

All i18n type definitions are of type 'any' #26022

EvanShaw opened this issue Oct 12, 2020 · 4 comments
Labels
Needs Dev Ready for, and needs developer efforts npm Packages Related to npm packages [Package] i18n /packages/i18n [Type] Bug An existing feature does not function as intended

Comments

@EvanShaw
Copy link

Describe the bug
Type definitions in default-i18n.d.ts for the @wordpress/i18n package generated by npm run build:package-types are all of type any. For example, the __ function definition looks like this:

/**
 * Retrieve the translation of text.
 *
 * @see https://developer.wordpress.org/reference/functions/__/
 *
 * @param {string} text     Text to translate.
 * @param {string} [domain] Domain to retrieve the translated text.
 *
 * @return {string} Translated text.
 */
export const __: any;

To reproduce
Steps to reproduce the behavior:

  1. npm run build:package-types
  2. Or, from a plugin/theme context, after installing @wordpress/i18n, import the function: import { __ } from '@wordpress/i18n'

Expected behavior
I expect the type definitions to be similar, if not the same, as described in #18942, like so:

/**
 * Retrieve the translation of text.
 *
 * @see https://developer.wordpress.org/reference/functions/__/
 *
 * @param {string} text     Text to translate.
 * @param {string} [domain] Domain to retrieve the translated text.
 *
 * @return {string} Translated text.
 */
export function __(text: string, domain?: string | undefined): string;

Screenshots
I'm developing a plugin with TypeScript React that uses the @wordpress/i18n package and excludes it from my webpack build. The following screenshot is what intellisense shows me in vscode (sorry about the small screenshot):

i18n-intellisense

@annezazu annezazu added [Package] i18n /packages/i18n [Type] Bug An existing feature does not function as intended Internationalization (i18n) Issues or PRs related to internationalization efforts Needs Dev Ready for, and needs developer efforts labels Oct 26, 2020
@gziolo
Copy link
Member

gziolo commented Nov 8, 2020

@sirreal, any idea why it might generate incorrect type definition?

@gziolo gziolo added npm Packages Related to npm packages and removed Internationalization (i18n) Issues or PRs related to internationalization efforts labels Nov 8, 2020
@sirreal
Copy link
Member

sirreal commented Nov 9, 2020

👋 Thanks for the report and the ping! I hadn't seen this report, but I took a look and suspect that I (inadvertently) fixed this in #26171. Not that this doesn't appear to be released on npm yet.

I've just compiled latest master and the results are accurate types:

/**
 * @typedef {import('./create-i18n').LocaleData} LocaleData
 */
/**
 * Merges locale data into the Tannin instance by domain. Accepts data in a
 * Jed-formatted JSON object shape.
 *
 * @see http://messageformat.github.io/Jed/
 *
 * @param {LocaleData} [data]   Locale data configuration.
 * @param {string}     [domain] Domain for which configuration applies.
 */
export const setLocaleData: (data?: Record<string, any> | undefined, domain?: string | undefined) => void;
/**
 * Retrieve the translation of text.
 *
 * @see https://developer.wordpress.org/reference/functions/__/
 *
 * @param {string} text     Text to translate.
 * @param {string} [domain] Domain to retrieve the translated text.
 *
 * @return {string} Translated text.
 */
export const __: (text: string, domain?: string | undefined) => string;
/**
 * Retrieve translated string with gettext context.
 *
 * @see https://developer.wordpress.org/reference/functions/_x/
 *
 * @param {string} text     Text to translate.
 * @param {string} context  Context information for the translators.
 * @param {string} [domain] Domain to retrieve the translated text.
 *
 * @return {string} Translated context string without pipe.
 */
export const _x: (text: string, context: string, domain?: string | undefined) => string;
/**
 * Translates and retrieves the singular or plural form based on the supplied
 * number.
 *
 * @see https://developer.wordpress.org/reference/functions/_n/
 *
 * @param {string} single   The text to be used if the number is singular.
 * @param {string} plural   The text to be used if the number is plural.
 * @param {number} number   The number to compare against to use either the
 *                          singular or plural form.
 * @param {string} [domain] Domain to retrieve the translated text.
 *
 * @return {string} The translated singular or plural form.
 */
export const _n: (single: string, plural: string, number: number, domain?: string | undefined) => string;
/**
 * Translates and retrieves the singular or plural form based on the supplied
 * number, with gettext context.
 *
 * @see https://developer.wordpress.org/reference/functions/_nx/
 *
 * @param {string} single   The text to be used if the number is singular.
 * @param {string} plural   The text to be used if the number is plural.
 * @param {number} number   The number to compare against to use either the
 *                          singular or plural form.
 * @param {string} context  Context information for the translators.
 * @param {string} [domain] Domain to retrieve the translated text.
 *
 * @return {string} The translated singular or plural form.
 */
export const _nx: (single: string, plural: string, number: number, context: string, domain?: string | undefined) => string;
/**
 * Check if current locale is RTL.
 *
 * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
 * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
 * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
 * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
 *
 * @return {boolean} Whether locale is RTL.
 */
export const isRTL: () => boolean;
export type LocaleData = {
    [x: string]: any;
};
//# sourceMappingURL=default-i18n.d.ts.map

I'll close because this should be improved as soon as the package is released.

@sirreal sirreal closed this as completed Nov 9, 2020
@EvanShaw
Copy link
Author

EvanShaw commented Dec 8, 2020

@sirreal

Sorry about the bump but this fix has yet to be released. Do you know when it will be published?

@sirreal
Copy link
Member

sirreal commented Dec 8, 2020

No problem. I believe this comment applies: #26866 (comment). The package releases are on hold until the WordPress release is complete. They should begin again in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Dev Ready for, and needs developer efforts npm Packages Related to npm packages [Package] i18n /packages/i18n [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants