question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate types for paths

See original GitHub issue

Describe the problem

  • Consider the base variable
  • Consider other paths on the same site, but outside of kit (special type in App?)
  • Consider external links
  • Slugs types need to be taken from params
  • Consider hash, parameters, different protocols
  • Use these types in kit wherever possible (redirect, load params, …)

Example:

/*
existing paths:
[
    "/",
    "/blog",
    "/blog/post/[post]",
    "/blog/tag/[tag=integer]",
    "/shop/[...slugs]",
]
*/

throw redirect(301, "/");
throw redirect(301, "/blog");
throw redirect(301, "/blog/qwe"); //type error
throw redirect(301, "/blog/post"); //type error
throw redirect(301, "/blog/post/qwe");
throw redirect(301, "/blog/tag/1");
throw redirect(301, "/blog/tag/qwe"); //type error
throw redirect(301, "/shop"); //type error
throw redirect(301, "/shop/a/b/c");
throw redirect(301, "https://www.google.com");
throw redirect(301, "/qwe"); //external

Describe the proposed solution

It is interesting:

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Oct 1, 2022

This would work in the short-term, but it would likely be difficult to make it work longer-term if we allow you to do things like have routes in multiple sub-projects and register routes from a different sub-project

0reactions
DanielHritcucommented, Nov 3, 2022

I stumbled upon this https://github.com/mattpocock/make-route-map

By replacing the param matcher :id with svelte [id] I can generate a routeMap.

For now, I crawl the routes folder and generate an index.ts. It would be great if this could be done by svelte in the sync stage and offer an import, and replace the function with static value similar to env/static

Read more comments on GitHub >

github_iconTop Results From Across the Web

paths - TSConfig Option - TypeScript
All of the common types in TypeScript ... How TypeScript infers types based on runtime behavior ... How to create and type JavaScript...
Read more >
LeetCode-OpenSource/typed-path-generator - GitHub
A more effective way to handle path parameters, which works perfectly with Typescript - GitHub - LeetCode-OpenSource/typed-path-generator: A more ...
Read more >
Create object property string path generator with typescript
Now, using this amazing feature we can create a type with infinite recursion and a helper function to generate all possible property paths...
Read more >
Making a file path mapper with Typescript - Level Up Coding
It receives a startDirectory parameter, which is exactly our rummage entry point. The mapping will only take the files inside the start directory....
Read more >
Typescript: How to convert an object type to paths mapper?
Paths_ is a recursive type which traverses through the object. It builds a union with a tuple of string | number for each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found