You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're loading files async at runtime, which makes it impossible to have end to end type safety during development.
I think Prisma has a similar issue (just with database schemas, instead of async file fetching) and the only solution is to generate types manually from a state X of the filesystem
In order to have this working we need to configure something project wise, so that if you have multiple instances to elysia-autoroutes you could generate the type for all of those directories.
Ideally I'd like to have:
an autoroutes command which can:
generate: if a file autoroutes.json is present, parse it and assume it's an array of strings of routesDir. If it's not available, scan the AST of all the ts/js/tsx/jsx files in the project, looking for calls to autoroutes, collect routesDir. For each routesDir, generate a file in node_modules/.autoroutes/router-${myRoutesDir}.ts which requires all the files and generate the correct types for the routers
preload-paths: run the logic in generate and save the paths to autoroutes.json
generate --watch: run generate and watches for file changes in the routes directories (not in all the projects, scanning for AST, that'd be a perf nightmare)
When the user is using the autoroutes plugin, get the type from node_modules/.autoroutes/router-${myRoutesDir}.ts the and cast the router to that type (but still load it dynamically at runtime)
Runtime behaviour will be unchanged, we should just get better types instead of unknown
What do you think? I might try to sketch something
The text was updated successfully, but these errors were encountered:
Thanks for the work on this module!
I have a suggestion on how to get types for Eden.
We're loading files async at runtime, which makes it impossible to have end to end type safety during development.
I think Prisma has a similar issue (just with database schemas, instead of async file fetching) and the only solution is to generate types manually from a state X of the filesystem
In order to have this working we need to configure something project wise, so that if you have multiple instances to elysia-autoroutes you could generate the type for all of those directories.
Ideally I'd like to have:
generate
: if a fileautoroutes.json
is present, parse it and assume it's an array of strings ofroutesDir
. If it's not available, scan the AST of all the ts/js/tsx/jsx files in the project, looking for calls to autoroutes, collectroutesDir
. For eachroutesDir
, generate a file innode_modules/.autoroutes/router-${myRoutesDir}.ts
which requires all the files and generate the correct types for the routerspreload-paths
: run the logic ingenerate
and save the paths toautoroutes.json
generate --watch
: run generate and watches for file changes in the routes directories (not in all the projects, scanning for AST, that'd be a perf nightmare)node_modules/.autoroutes/router-${myRoutesDir}.ts
the and cast the router to that type (but still load it dynamically at runtime)Runtime behaviour will be unchanged, we should just get better types instead of unknown
What do you think? I might try to sketch something
The text was updated successfully, but these errors were encountered: