-
Notifications
You must be signed in to change notification settings - Fork 307
Open
Description
I got a Typescript syntax error for following code similar to what is in the readme page
const convert = configureMeasurements({
volume,
mass,
});Syntax error:
Type 'Measure<MassSystems, MassUnits>' is not assignable to type 'Measure<MassSystems, VolumeUnits>'.
The types of 'systems.metric' are incompatible between these types.
Type 'Partial<Record<MassUnits, Unit>> | undefined' is not assignable to type 'Partial<Record<VolumeUnits, Unit>> | undefined'.
Type 'Partial<Record<MassUnits, Unit>>' has no properties in common with type 'Partial<Record<VolumeUnits, Unit>>'.ts(2322)
Typescript compiler seemed to be confused with generic types in this closure and could not figure out what went with what. All three types TMeasures, TSystems and TUnits were linked. It would not make sense to mix and match them.
Here is the work-around that got rid of the syntax error:
const convert = configureMeasurements<"volume" | "mass", VolumeSystems | MassSystems, VolumeUnits | MassUnits>({
volume,
mass,
});As you could see, it was a bit awkward to use. Could it be possible to redefine all of them as a single type and make it easier for Typescript to figure out?
Typescript version: 4.2.4
convert-units version: 3.0.0-beta.2
JoJk0 and connor-baer
Metadata
Metadata
Assignees
Labels
No labels