[convert-units] Make convert function value param optional. (#44225)

The `convert` function can be used with no `value` argument, but previously the type definition for this module required it.

- Made `value` param to `convert` function optional.
- Added tests for that use case.
This commit is contained in:
Toby Bell 2020-04-26 10:16:47 -07:00 committed by GitHub
parent dba40a97b6
commit 29ece6dcb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -4,3 +4,16 @@ const convertedMass = convert(25).from('mcg').to('t');
const convertedMassBack = convert(convertedMass).from('t').to('mcg');
const unit = convert(66).getUnit<'mcg'>('mcg');
// Using `convert` without a value.
const measures = convert().measures();
const allUnits = convert().possibilities();
const massUnits = convert().possibilities('mass');
const distanceUnits = convert().from('m').possibilities();
const kgDescription = convert().describe('kg');
const kgAbbr: string = kgDescription.abbr;
const kgMeasure: string = kgDescription.measure;
const kgSystem: string = kgDescription.system;
const kgSingular: string = kgDescription.singular;
const kgPlural: string = kgDescription.plural;

View File

@ -2,6 +2,7 @@
// Project: https://github.com/ben-ng/convert-units#readme
// Definitions by: vladkampov <https://github.com/vladkampov>
// ben-ng <https://github.com/ben-ng>
// Toby Bell <https://github.com/tobybell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
@ -129,6 +130,6 @@ declare class Convert {
measures(): measure[];
}
declare function convert(value: number): Convert;
declare function convert(value?: number): Convert;
export = convert;