diff --git a/.changeset/thirty-crabs-shout.md b/.changeset/thirty-crabs-shout.md new file mode 100644 index 000000000..4c44ed672 --- /dev/null +++ b/.changeset/thirty-crabs-shout.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix module definition of Markdown and MDX files not being available outside Astro files diff --git a/packages/astro/client-base.d.ts b/packages/astro/client-base.d.ts index 1219e150c..829033923 100644 --- a/packages/astro/client-base.d.ts +++ b/packages/astro/client-base.d.ts @@ -1,5 +1,39 @@ /// +declare module '*.md' { + type MD = import('./dist/@types/astro').MarkdownInstance>; + + export const frontmatter: MD['frontmatter']; + export const file: MD['file']; + export const url: MD['url']; + export const getHeadings: MD['getHeadings']; + /** @deprecated Renamed to `getHeadings()` */ + export const getHeaders: () => void; + export const Content: MD['Content']; + export const rawContent: MD['rawContent']; + export const compiledContent: MD['compiledContent']; + + const load: MD['default']; + export default load; +} + +declare module '*.mdx' { + type MDX = import('./dist/@types/astro').MDXInstance>; + + export const frontmatter: MDX['frontmatter']; + export const file: MDX['file']; + export const url: MDX['url']; + export const getHeadings: MDX['getHeadings']; + export const Content: MDX['Content']; + export const rawContent: MDX['rawContent']; + export const compiledContent: MDX['compiledContent']; + + const load: MDX['default']; + export default load; +} + +// Everything below are Vite's types (apart from image types, which are in `client.d.ts`) + // CSS modules type CSSModuleClasses = { readonly [key: string]: string }; diff --git a/packages/astro/env.d.ts b/packages/astro/env.d.ts index a579d78ce..10a61b06f 100644 --- a/packages/astro/env.d.ts +++ b/packages/astro/env.d.ts @@ -1,8 +1,13 @@ /// +// Caution! The types here are only available inside Astro files (injected automatically by our language server) +// As such, if the typings you're trying to add should be available inside ex: React components, they should instead +// be inside `client-base.d.ts` + type Astro = import('./dist/@types/astro').AstroGlobal; -// We duplicate the description here because editors won't show the JSDoc comment from the imported type (but will for its properties, ex: Astro.request will show the AstroGlobal.request description) +// We have to duplicate the description here because editors won't show the JSDoc comment from the imported type +// However, they will for its properties, ex: Astro.request will show the AstroGlobal.request description /** * Astro global available in all contexts in .astro files * @@ -12,38 +17,6 @@ declare const Astro: Readonly; declare const Fragment: any; -declare module '*.md' { - type MD = import('./dist/@types/astro').MarkdownInstance>; - - export const frontmatter: MD['frontmatter']; - export const file: MD['file']; - export const url: MD['url']; - export const getHeadings: MD['getHeadings']; - /** @deprecated Renamed to `getHeadings()` */ - export const getHeaders: () => void; - export const Content: MD['Content']; - export const rawContent: MD['rawContent']; - export const compiledContent: MD['compiledContent']; - - const load: MD['default']; - export default load; -} - -declare module '*.mdx' { - type MDX = import('./dist/@types/astro').MDXInstance>; - - export const frontmatter: MDX['frontmatter']; - export const file: MDX['file']; - export const url: MDX['url']; - export const getHeadings: MDX['getHeadings']; - export const Content: MDX['Content']; - export const rawContent: MDX['rawContent']; - export const compiledContent: MDX['compiledContent']; - - const load: MDX['default']; - export default load; -} - declare module '*.html' { const Component: { render(opts: { slots: Record }): string }; export default Component; diff --git a/packages/astro/tsconfig.json b/packages/astro/tsconfig.json index a51690d2a..6be154d55 100644 --- a/packages/astro/tsconfig.json +++ b/packages/astro/tsconfig.json @@ -6,7 +6,6 @@ "declarationDir": "./dist", "module": "ES2020", "outDir": "./dist", - "target": "ES2020", - "types": ["./client"] + "target": "ES2020" } }