Feat: Improve generated types to include optional types#697
Feat: Improve generated types to include optional types#697bakerkretzmar merged 19 commits intotighten:2.xfrom
Conversation
|
@bakerkretzmar Howdy, what do you think about this? It makes knowing the expected params for a route much easier |
|
@alexmccabe thanks for doing this! I added type KnownRouteParamsObject<I extends readonly ParameterInfo[]> = {
[T in I[number] as T['name']]: T extends { optional: true } ? Routable<T> | undefined : Routable<T>;
} & GenericRouteParamsObject;But that doesn't actually make those properties optional.... One last question here—the type errors I get when a
|
|
Also wondering if we should call this |
|
@bakerkretzmar I tried to do that with the I can see if I can make the suggested improvements, then will update to use |
|
So I have managed to get this far, which I think is a bit of an improvement to the end types being flat. What do you think? |
|
In regards to the weird type error given, this is due to the looseness of the If I create another function overload, then it behaves as expected: export default function route<T extends RouteName>(
name: T,
params?: ParameterValue | undefined,
absolute?: boolean,
config?: Config,
): string; |
|
I managed to fix the failing test, however I'm not sure if it's a good solution that I did. Anyways, lemme know your thoughts, since I think I've addressed everything, except the |
Wip/improve types further
|
@bakerkretzmar I just merged the branch into here, any extra thoughts on this? |
|
@bakerkretzmar Howdy buddy, hope everything is okay. This has been sat for a while, I don't want to be annoying of course though |
|
@alexmccabe no worries, I've been travelling for the past several weeks! I'll take a more thorough look at this again when I'm home later this month! Appreciate it. |
|
@bakerkretzmar No worries, I hope you had a nice time travelling. Did you get a chance to look around this? |
|
@alexmccabe thanks a ton for your patience 🙏🏻 messed around with this some more and finally figured out some slightly simpler utility types that I'm happy with. The resulting type has an extra union which is a bit uglier, but I'm fine with that trade-off for the type definitions to be cleaner. Playground for future reference. Just going to double-check that the array argument thing was already an issue and didn't appear in this PR and then I'll get this merged! |
|
That's okay buddy, Open Source can take time. Thank you for considering the work! |


Improve the generated typescript file to include optional params on
KnownRouteParamsobject, instead of marking everything as optional