Typescript: NumberFormatOptions is missing several options including notation

Created on 30 Jan 2020  路  6Comments  路  Source: microsoft/TypeScript

notation is missing from NumberFormatOptions

https://github.com/microsoft/TypeScript/blob/91ffa1c752ac26882b1426fb4c9012701c1d908e/lib/lib.es5.d.ts#L4236


TypeScript Version: 3.7.5


Search Terms: NumberFormatOptions notation

Code

const str = new Intl.NumberFormat(undefined, {notation: 'scientific'}).format(100000);

https://github.com/chartjs/Chart.js/blob/5f24b97bbfff52975c801b0a0b8880b2aa3b0a6a/src/core/core.ticks.js#L57

Expected behavior:

I should be able to use NumberFormat's notation option. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat

Actual behavior:

src/core/core.ticks.js(57,43): error TS2345: Argument of type '{ notation: string; minimumFractionDigits: number; maximumFractionDigits: number; }' is not assignable to parameter of type 'NumberFormatOptions'.

Playground Link: None

Related Issues: None

Bug lib.d.ts help wanted

Most helpful comment

@MartinJohns notation is not experimental anymore. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/NumberFormat

Can this issue be reopened or I can create a new one if preffered?

All 6 comments

Commonly the TypeScript team does not add experimental APIs to the standard library definitions.

You can use Declaration Merging to extend the types yourself. There's probably also a npm package out there that does this for you.

Thanks!

@MartinJohns notation is not experimental anymore. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/NumberFormat

Can this issue be reopened or I can create a new one if preffered?

@MartinJohns notation is not experimental anymore. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/NumberFormat

Can this issue be reopened or I can create a new one if preffered?

same need +1

@benmccann Any workaround for this for now?

@benmccann Any workaround for this for now?

const shortAmount = new Intl.NumberFormat(undefined, {
  //@ts-ignore
   notation: "compact",
  compactDisplay: "short"
}).format(parseInt(value));

I think the only solution for now is to add a ts-ignore until the types definitions are updated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanzer picture seanzer  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

dlaberge picture dlaberge  路  3Comments