I'm using path aliases and manifest files for cleaner imports. For example, here's a page that imports a component (e.g. pages/index.astro):
---
import { Card, PageHeader } from '@components'
import { Layout } from '@layouts'
---
<Layout title="...">
...
The manifest files look like this:
// components/index.ts
import Card, { Props as CardProps } from './Card.astro'
export { Card }
export type { CardProps }
And tsconfig.json:
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@components": ["src/components/index"],
"@layouts": ["src/layouts/index"],
"@content": ["content/utils/index"],
"@/*": ["./*"]
}
}
}
This works fine in dev mode and in VS Code. But there are two issues:
astro checkpasses, buttsc --noEmitfails with this setup.- If I try to import using aliases in a manifest file (e.g.
import Card from '@/components/Card.astro), VS Code doesn't like it.
Error for #1 is:
Cannot find module './Card.astro' or its corresponding type declarations.