-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[astro-when] Type Errors for some gosh darn reason #156
Comments
The types for the virtual modules rely on TS side-effect loading logic, which seems to only be working when your Astro config is a TS file ( I plan to fix this, so I'll leave this issue open for tracking. With the types loaded, you'll still see two other type errors on the code you sent; those errors are correct and point to mistakes in the code. The first one is this: const middlewares: Record<When, MiddlewareHandler> = {
[When.Client]: (context, next) => handleRequest(context, next),
[When.DevServer]: (_, next) => next(),
[When.Server]: (_, next) => next(),
}; The type The second error is this: export const onRequest = defineMiddleware(middlewares[whenAmI()]);
- export const onRequest = defineMiddleware(middlewares[whenAmI()]);
+ export const onRequest = defineMiddleware(middlewares[whenAmI]); If you switch to const noopMiddleware = defineMiddleware((_, next) => next());
export const onRequest = defineMiddleware(middlewares[whenAmI] ?? noopMiddleware); |
That is not the behavior on the repro. Can you share your I know |
{
"extends": "astro/tsconfigs/strict",
"include": ["src/**/*", ".astro/**/*.ts", ".astro/**/*.d.ts"],
"exclude": ["dist", "functions", "node_modules"],
"compilerOptions": {
"jsx": "preserve",
"baseUrl": ".",
"moduleResolution": "Bundler",
"paths": {
"appwrite": ["node_modules/appwrite"],
"@/*": ["src/*"],
"@appwrite/*": ["src/appwrite/*"],
"@assets/*": ["src/assets/*"],
"@constants/*": ["src/constants/*"],
"@components/*": ["src/components/*"],
"@layouts/*": ["src/layouts/*"],
"@pages/*": ["src/pages/*"],
"@server/*": ["src/server/*"],
"@utils/*": ["src/utils/*"],
"@stores/*": ["src/stores/*"],
"@vue/*": ["src/components/vue/*"]
}
}
} |
Okay, I managed to reproduce. TS is not loading your Astro config because it doesn't match any of the Adding it there made my reproduction work. In parallel, I opened #157 which will use Astro's new |
https://stackblitz.com/edit/github-4vqrvw?file=astro.config.mjs
I keep getting type errors when installing (hah) and trying to use
astro-when
, am I doing something wrong? I didn't add theenv.d.ts
//reference
types to this one, but on my new project I have the same error even with the reference typesThe text was updated successfully, but these errors were encountered: