Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react-intl libdef: Add
typeof
to Intl.PluralRules in some places
This fixes one of the things Flow glosses over and would catch when we migrate this to a .js.flow file, with an error like this: Error -------------------- flow-typed/react-intl_vx.x.x.js:353:36 Cannot use `PluralRules` as a type. A name can be used as a type only if it refers to a type, interface, class, or enum definition. To get the type of a non-class value, use `typeof`. [value-as-type] 353| pluralRules: {| [key: string]: Intl.PluralRules |}; ^^^^^^^^^^^^^^^^ I think this is what's going on: Flow treats Intl.Foo as a value, because Intl is a `declare var`, not a `declare type` [1]: declare var Intl: { Collator: Class<Intl$Collator>, DateTimeFormat: Class<Intl$DateTimeFormat>, NumberFormat: Class<Intl$NumberFormat>, PluralRules: ?Class<Intl$PluralRules>, getCanonicalLocales?: (locales?: Intl$Locales) => Intl$Locale[], ... } I think that means that if we want to use the declared type of an Intl.Foo, we'd normally want to use `typeof Intl.Foo`. But most of the actual Intl members with `Class<…>` are special, because a class value can be used as a type without `typeof`. I think Intl.PluralRules doesn't get that special treatment, because it's got `?Class<…>` -- which expands to the union type `Class<…> | null | void`. Union types aren't class definitions, so the special treatment doesn't apply and we should use `typeof`. [1] https://github.com/facebook/flow/blob/v0.141.0/lib/intl.js#L8-L15
- Loading branch information