10 Oct 2023 11:39 AM - last edited on 10 Oct 2023 11:56 AM by stefan_eggersto
Hello,
(do no worries everything works now (-;)
Small question about below,
const formatter: FormatOptions<Unit, ConvertableUnit> = {
maximumFractionDigits: chartPrecision,
This means we have a formatter of type FormatOptions expecting two props.
Where in the documentation can I find the FormatOptions type?
I assume this is the interface input-ToUnid and output-FromUnit but I guess this is defined in the Runtime,
Am I missing something?
KR Henk
Solved! Go to Solution.
10 Oct 2023 11:56 AM
Hi again 🙂
You can find the type reference at https://developer.dynatrace.com/reference/sdks/units/#formatoptions
The properties of FormatOptions
tell the formatter how it should behave, for example, to which unit it should convert the input or if it should abbreviate the number.
10 Oct 2023 12:44 PM
Stefan please make my day😀
Looking at your link,
Is const formatter: FormatOptions<ToUnit, ConvertableUnit>
Not a better, or am I still missing something?
KR Henk
16 Oct 2023 12:17 PM
Hi @henk_stobbe ,
It took me some time to dig into that since the typing of this package is all but trivial. Long story short:
ConvertableUnit
) and type parameters (FromUnit
and ToUnit
). Only types should be documented there.formatter
needs to refer to types, so only const formatter: FormatOptions<Unit, ConvertableUnit>
is valid, but not const formatter: FormatOptions<FromUnit, ToUnit>
Now the longer story with some background information 🙂 The relevant parts of the type definition of FormatOptions
is following:
export interface FormatOptions<FromUnit extends Unit, ToUnit extends ConvertableUnit> {
...
input?: FromUnit;
output?: ToUnit;
...
}
FormatOptions
is a generic interface with two type parametersUnit
and ConvertableUnit
are types provided by the SDK. units.currency.usd
satisfies the type Unit
, so you can write the following valid assignment: const myUnit: Unit = units.currency.usd;
FromUnit
and ToUnit
are just the names of the type parameters and only valid within this type definitionFromUnit
needs to be any type that extends Unit
, ToUnit
needs to be any type that extends ConvertableUnit
Unit
and ConvertableUnit
are relevant for consumers, ToUnit
and FromUnit
are just the names of the type parameters of FormatterOptions.
16 Oct 2023 01:56 PM
Hello Stefan,
I realy wish I could give you more the one Kudo, great answer. Sorry for giving you the extra work.
It helped met to better understand,
Thx!
17 Oct 2023 11:31 AM
Great answer (tip) - thank you!