2 comments

[ 4.9 ms ] story [ 13.5 ms ] thread
Is there a way to achieve this without the method chaining DSL?
Maybe? An alternative API might look something this:

  route("path", "to", IntParam("myArg"))
TypeScript doesn't support properly typing variadic functions yet though.[1] So you can't type this properly for an arbitrary number of parameters. You could try overloading the function definition for a fixed number of parameters, but that could get messy really fast.

An alternate approach might involve regex-validated types[2], if/when those get implemented, though I'm not sure how that'd work exactly.

[1] https://github.com/Microsoft/TypeScript/issues/5453

[2] https://github.com/Microsoft/TypeScript/issues/6579