Generate types for paths
See original GitHub issueDescribe 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:
- https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html
- https://lihautan.com/extract-parameters-type-from-string-literal-types-with-typescript/
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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 toenv/static