Closed audunolsen closed 1 year ago
I guess I can just do this instead of course, which works fine.
I'm new to this lib and this approach to typescript, so I may have misunderstood the purpose of zip. I thought you could wrap any value in a tuple with it? So I'm not sure if this is an actual issue or just me not understanding it properly.
Weird, this look like some sort of bug. I'll take a look.
Here is an alternative implementation using Objects.Create
, which takes a data structure and evaluates any function inside of it with the current arguments:
type RouteParams<T extends string> = Pipe<
T,
[
Strings.Split<"/">,
Tuples.Filter<Strings.StartsWith<":">>,
Tuples.Map<Objects.Create<[Strings.Trim<":">, string]>>,
Tuples.ToUnion,
Objects.FromEntries
]
>;
type x = RouteParams<"/users/:user/friends/:friend">
I think I fixed the issue: Playground
Attemnpting to make a route-function similar to the example shown in the readme, but simpler. Above code causes ts-error.
Type instantiation is excessively deep and possibly infinite. ts(2589)
. TogglingTuples.Zip
seems to trigger the error. In above example zip is utilised to transform["user", "friend"]
to[["user"], ["friend"]]
and then mapping the latter to[["user", string], ["friend", string]]
and then ultimately to the final object. Thoughts?TS-playground repro.