4 ms·
Is there a way to achieve this without the method chaining DSL?
by pspeter3 9y ago
Is there a way to achieve this without the method chaining DSL?
- andrewfong 9y agoMaybe? 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