
Typed Routes with TypeScript - andrewfong
https://tech.esper.com/2017/08/04/typed-routes-with-typescript/
======
pspeter3
Is there a way to achieve this without the method chaining DSL?

~~~
andrewfong
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](https://github.com/Microsoft/TypeScript/issues/5453)

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

