Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Typed Routes with TypeScript (esper.com)
4 points by andrewfong on Aug 4, 2017 | hide | past | favorite | 2 comments


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: