You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Duration and DataSize types in the Pkl standard library have excellent rich APIs (see Duration and DataSize) for converting between units and comparing (or eg. summing) values
We 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 with unit and value 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).
The text was updated successfully, but these errors were encountered:
jasongwartz
changed the title
Support Duration and Datasize types
Rich APIs for Duration and Datasize types
Mar 30, 2024
@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).
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!
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
).The text was updated successfully, but these errors were encountered: