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:
parent
849fefd8b0
commit
7690849a87
4 changed files with 46 additions and 35 deletions
5
.changeset/thirty-crabs-shout.md
Normal file
5
.changeset/thirty-crabs-shout.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix module definition of Markdown and MDX files not being available outside Astro files
|
34
packages/astro/client-base.d.ts
vendored
34
packages/astro/client-base.d.ts
vendored
|
@ -1,5 +1,39 @@
|
||||||
/// <reference path="./import-meta.d.ts" />
|
/// <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
|
// CSS modules
|
||||||
type CSSModuleClasses = { readonly [key: string]: string };
|
type CSSModuleClasses = { readonly [key: string]: string };
|
||||||
|
|
||||||
|
|
39
packages/astro/env.d.ts
vendored
39
packages/astro/env.d.ts
vendored
|
@ -1,8 +1,13 @@
|
||||||
/// <reference path="./client.d.ts" />
|
/// <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;
|
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
|
* Astro global available in all contexts in .astro files
|
||||||
*
|
*
|
||||||
|
@ -12,38 +17,6 @@ declare const Astro: Readonly<Astro>;
|
||||||
|
|
||||||
declare const Fragment: any;
|
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' {
|
declare module '*.html' {
|
||||||
const Component: { render(opts: { slots: Record<string, string> }): string };
|
const Component: { render(opts: { slots: Record<string, string> }): string };
|
||||||
export default Component;
|
export default Component;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
"declarationDir": "./dist",
|
"declarationDir": "./dist",
|
||||||
"module": "ES2020",
|
"module": "ES2020",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"target": "ES2020",
|
"target": "ES2020"
|
||||||
"types": ["./client"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue