Move module declarations for Markdown and MDX so they're available everywhere (#4928)

* Move module declarations for Markdown and MDX to the proper file so they're globally available

* Remove tsconfig.json depending on client.d.ts unnecessarily
This commit is contained in:
Erika 2022-09-30 12:06:14 -03:00 committed by GitHub
parent 849fefd8b0
commit 7690849a87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 35 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix module definition of Markdown and MDX files not being available outside Astro files

View file

@ -1,5 +1,39 @@
/// <reference path="./import-meta.d.ts" />
declare module '*.md' {
type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
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<Record<string, any>>;
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 };

View file

@ -1,8 +1,13 @@
/// <reference path="./client.d.ts" />
// 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<Astro>;
declare const Fragment: any;
declare module '*.md' {
type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
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<Record<string, any>>;
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, string> }): string };
export default Component;

View file

@ -6,7 +6,6 @@
"declarationDir": "./dist",
"module": "ES2020",
"outDir": "./dist",
"target": "ES2020",
"types": ["./client"]
"target": "ES2020"
}
}