Replies: 2 comments 4 replies
-
@Gozala Thanks for surfacing this! I'm not totally clear on why there's no good way to type this in TS. It's true that the caveats are KV by design. For the required fields, is it not possible to use intersection types in TypeScript? We have no problem capturing this information in the Haskell or Rust type systems, but we also have an actual parser in between rather than relying directly on JSON 🤔 |
Beta Was this translation helpful? Give feedback.
-
Yeah it has no generics but then also when e.g. validate struct with a schema if underlying data has more fields it will not validate. alternatively you could type capability not as a struct but a KV map in which case it would validate but then it may not have can / with. Although your comment got me an idea that in IPLD I don't have to map 1:1 with JSON structure e.g. I could type it as:
When formatting it into JWT |
Beta Was this translation helpful? Give feedback.
-
Right now spec defines structure of capability as follows
I have been running into various limitations that I would like to surface
1. Capturing constraints in types
Right now capability type in TS can be expressed more or less as:
But there is no simple way to capture capability constraints as there is no placeholder field for them. So in TS I find myself resorting to types like:
It would have been a lot simpler if constraints were under dedicated field e.g.
2. IPLD Schemas
In less powerful type systems like IPLD schemas you simply cant specify open ended types with arbitrary fields so you either have to treat
Capability
as a key value map (and have upholdwith
andcan
invariants out of bound) or just add a comment likeUnfortunately comments aren't going to help with schema validators (as they structs must match exactly) or parser generators.
On the other hand if constraints had dedicated field it would be possible to express that without any problems
Beta Was this translation helpful? Give feedback.
All reactions