Open jasongwartz opened 7 months ago
Hello can you please elaborate, what do you mean by similar helper APIs
, maybe you could provide an example?
@DmitryPR Have you used these types in Pkl? I've linked the API documentation above - there are functions like toUnit()
, so in Pkl, you can do things like 75.s.toUnit("min").value
(to get 75 seconds in minutes).
Here's how pkl-go
has implemented it, which isn't far off of what we have so far: https://github.com/apple/pkl-go/blob/main/pkl/values.go#L92
But it would be useful if we had a Duration
class, that had, say, a similar 'toUnit()' function that returned another Duration
object in the converted unit.
Currently, the pkl-typescript Duration
and DataSize
types (as linked above) are just interface types - we would probably want to implement them as classes in order to support the richer APIs, and then instantiate the classes in the decoder logic.
If you're intested in helping contribute to pkl-typescript
, feel free to come join us on Discord (link documented here: https://github.com/pkl-community) and join the #bindings-typescript
channel!
Allright, now I see what you mean
The
Duration
andDataSize
types in the Pkl standard library have excellent rich APIs (see Duration and DataSize) for converting between units and comparing (or eg. summing) valuesWe have basic support for creating TS objects with the properties that come over the wire from
pkl server
(see here) but those are just key-value pair objects withunit
andvalue
properties.We could consider writing custom class implementations that have similar helper APIs to the Pkl equivalents. We could also consider using
valueOf
or Proxy to allow mathematical operators (eg.myDataSizeA - myDataSizeB
).