Skip to content

Commit 165603c

Browse files
fix: extend branding interface to unit-keys-value
1 parent 6694e3c commit 165603c

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/core.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Exponent } from "./exponents";
55
import type {
66
BrandUnitClass,
77
BrandUnitClassType,
8+
BrandUnitKeyValues,
89
BrandUnitMeta,
910
ExcludeUnitZeroSubvalues,
1011
RemoveNeverValues,
@@ -115,15 +116,12 @@ export type UnknownUnitMeta = UnknownUnitKeyValues &
115116
__uno_types__unit_meta_type: true;
116117
}>;
117118

118-
type UnitKeyValues<T extends UnitSubvalues> = Readonly<{
119-
__uom_types__keys: keyof ExcludeUnitZeroSubvalues<T> extends string ? keyof ExcludeUnitZeroSubvalues<T> : never;
120-
__uom_types__value: RemoveNeverValues<T>;
121-
}>;
119+
type UnitKeyValues<T extends UnitSubvalues> = BrandUnitKeyValues<
120+
keyof ExcludeUnitZeroSubvalues<T> extends string ? keyof ExcludeUnitZeroSubvalues<T> : never,
121+
RemoveNeverValues<T>
122+
>;
122123

123-
type UnknownUnitKeyValues = Readonly<{
124-
__uom_types__keys: string;
125-
__uom_types__value: {};
126-
}>;
124+
type UnknownUnitKeyValues = BrandUnitKeyValues<string, {}>;
127125

128126
/**
129127
* A mapping of subvalue of a unit its magnitude.

src/units/modifiers/exponentials.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export type Square<
2828
> = T extends number
2929
? Pow<T, 2>
3030
: T extends UnknownUnitClass
31-
? UnitClass<PowUnitSubvalues<T["__uom_types__value"], 2>>
31+
? UnitClass<PowUnitSubvalues<T["__uom_types"]["value"], 2>>
3232
: T extends UnknownUnitMeta
33-
? UnitMeta<PowUnitSubvalues<T["__uom_types__value"], 2>>
33+
? UnitMeta<PowUnitSubvalues<T["__uom_types"]["value"], 2>>
3434
: never;
3535

3636
/**
@@ -46,9 +46,9 @@ export type Cubic<
4646
> = T extends number
4747
? Pow<T, 3>
4848
: T extends UnknownUnitClass
49-
? UnitClass<PowUnitSubvalues<T["__uom_types__value"], 3>>
49+
? UnitClass<PowUnitSubvalues<T["__uom_types"]["value"], 3>>
5050
: T extends UnknownUnitMeta
51-
? UnitMeta<PowUnitSubvalues<T["__uom_types__value"], 3>>
51+
? UnitMeta<PowUnitSubvalues<T["__uom_types"]["value"], 3>>
5252
: never;
5353

5454
// Tests

src/units/modifiers/reciprocal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export type Reciprocal<
2626
> = T extends number
2727
? Inverse<T>
2828
: T extends UnknownUnitClass
29-
? UnitClass<InverseUnitSubvalues<T["__uom_types__value"]>>
29+
? UnitClass<InverseUnitSubvalues<T["__uom_types"]["value"]>>
3030
: T extends UnknownUnitMeta
31-
? UnitMeta<InverseUnitSubvalues<T["__uom_types__value"]>>
31+
? UnitMeta<InverseUnitSubvalues<T["__uom_types"]["value"]>>
3232
: never;
3333

3434
// Tests

src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ export type BrandUnitClassType = Brand & {
3636
};
3737
};
3838

39+
/**
40+
* Brand with the unit keys and value.
41+
*/
42+
export type BrandUnitKeyValues<K, V> = Brand &
43+
Readonly<{
44+
__uom_types: {
45+
keys: K;
46+
value: V;
47+
};
48+
}>;
49+
3950
/**
4051
* Remove all key from the object that are `never`.
4152
*/

0 commit comments

Comments
 (0)