Intl.NumberFormat.formatToParts 不是函数

Intl.NumberFormat.formatToParts is not a function

我在 React Native 中使用 Intl 命名空间来进行一些货币和公制金额格式化(W.h,等等) 使用 formatToParts 方法时,在 IOS 和 Android 调试模式下一切正常。但是在 Android 开发模式下,我有以下错误:

Intl.NumberFormat(_i18nJs.default.locale,options).formatToParts is not a function. (In 'Intl.NumberFormat(_i18n.Js.default.locale,options).formatToParts(value)','Intl.NumberFormat(_i18nJs.default.locale,options).formatToParts' is undefined)

在发布模式下,我使用此功能的屏幕使应用程序崩溃

代码:

public static formatNumberWithCompacts(value: number, options: FormatNumberOptions = {}): FormatNumberResult {
    const isCompactForm =
      options.notation === NumberFormatNotationEnum.COMPACT &&
      (!options.compactThreshold || (options.compactThreshold && value > options.compactThreshold));
    const isCurrency = options.currency && options.style === NumberFormatStyleEnum.CURRENCY;
    options.currency = options.currency || I18nManager.currency;
    const isUnit = options.unit && options.style === NumberFormatStyleEnum.UNIT;
    const isPercent = options.style === NumberFormatStyleEnum.PERCENT;

    if (!isCompactForm) {
      delete options.notation;
    }
    // Format the given value with the given options
    const parts = Intl.NumberFormat(i18n.locale, options).formatToParts(value);

我通过将此处指示的所有 polyfill 导入添加到我的 index.ts 来解决问题: https://github.com/web-ridge/react-native-paper-dates/releases/tag/v0.2.15

我还必须按照 Format.js 的文档中的说明预先安装每个 polyfill:https://formatjs.io/docs/polyfills