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

Type definition: wrong parameter types #749

Closed
lanyizi opened this issue Dec 5, 2019 · 0 comments · Fixed by #1096
Closed

Type definition: wrong parameter types #749

lanyizi opened this issue Dec 5, 2019 · 0 comments · Fixed by #1096
Labels
Type: Improvement Includes backwards-compatible fixes

Comments

@lanyizi
Copy link

lanyizi commented Dec 5, 2019

vue & vue-i18n version

Vue version 2.6.1, Vue-i18n version 8.15.1

Reproduction Link

https://jsfiddle.net/8svpywbg/2/

Steps to reproduce

Write this.$d(123456, { useGrouping: false });.

What is Expected?

From the documentation it looks like that when calling VueI18n's this.$n(number, key), one could also use an object as the parameter key. This object should be similar to (if not just being to an instance of) Intl.NumberFormat.

What is actually happening?

However, in Intl.NumberFormat, useGrouping's type is boolean, meanwhile this.$n() will only accept it if it's a string:

d(value: number | Date, args?: { [key: string]: string }): VueI18n.DateTimeFormatResult;

If someone write this.$n(number, { useGrouping: false }), typescript will give the following error:

No overload matches this call.
  Overload 1 of 2, '(value: number, key?: string | undefined, locale?: string | undefined): string', gave the following error.
    Argument of type '{ useGrouping: boolean; }' is not assignable to parameter of type 'string'.
  Overload 2 of 2, '(value: number, args?: { [key: string]: string; } | undefined): string', gave the following error.
    Argument of type '{ useGrouping: boolean; }' is not assignable to parameter of type '{ [key: string]: string; }'.
      Property 'useGrouping' is incompatible with index signature.
        Type 'boolean' is not assignable to type 'string'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Includes backwards-compatible fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants