Open mlhaufe opened 1 year ago
Some early notes on typing Trait
:
Since that was written, Trait
has has been updated to accept an instance of Data as it's first argument:
const and = Trait(Bool, {
False: (left, _) => left,
True: (_, right) => right
})
If Data
can be typed appropriately, then in theory there should be little to nothing to annotate on Trait
.
Current branch in progress: https://github.com/mlhaufe/brevity/tree/typescript
Desired usage (as of March 26):
This requires two features though:
Without this feature the end-user is required to annotate every
Data()
usage withas const
:Because of this issue, the desired syntax is not viable.
This works but the properties are of type
any
:This does not work:
TypeScript complains that the 2nd generic is not provided. It's all or nothing. It's not desirable to have the end-user copy/paste the arguments into the 2nd generic position:
Notice the additional syntactic overhead for this
Data
definition. From 1 line to 3 lines. Inlining the types make readability worse:An object literal is even worse.
In general I'm suspecting this is not worth the effort. To quote Tim Sweeney: