Skip to content

Commit d74617c

Browse files
authored
Refactor/types (#11715)
* refactor: types * feat: refactor types * chore: organize imports * fix: remaining references * docs: types * refactor: small changes * chore: changeset
1 parent 40b95a1 commit d74617c

216 files changed

Lines changed: 2079 additions & 2102 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/poor-frogs-dream.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Refactor the exported types from the `astro` module. There should normally be no breaking changes, but if you relied on some previously deprecated types, these might now have been fully removed.
6+
7+
In most cases, updating your code to move away from previously deprecated APIs in previous versions of Astro should be enough to fix any issues.

.github/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@
4040
- packages/integrations/vue/**
4141

4242
'docs pr':
43-
- packages/astro/src/@types/astro.ts
43+
- packages/astro/src/types/public/**
4444
- packages/astro/src/core/errors/errors-data.ts

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- "examples/**"
1212
- ".github/workflows/check.yml"
1313
- "scripts/smoke/check.js"
14-
- "packages/astro/src/@types/astro.ts"
14+
- "packages/astro/src/types/public/**"
1515
- "pnpm-lock.yaml"
1616
- "packages/astro/types.d.ts"
1717

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ jobs:
229229
filters: |
230230
docs:
231231
- 'packages/integrations/*/README.md'
232-
- 'packages/astro/src/@types/astro.ts'
232+
- "packages/astro/src/types/public/**"
233233
- 'packages/astro/src/core/errors/errors-data.ts'
234234
235235
- name: Build autogenerated docs pages from current astro branch

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Server-side rendering (SSR) can be complicated. The Astro package (`packages/ast
289289

290290
- `components/`: Built-in components to use in your project (e.g. `import Code from 'astro/components/Code.astro'`)
291291
- `src/`: Astro source
292-
- `@types/`: TypeScript types. These are centralized to cut down on circular dependencies
292+
- `types/`: TypeScript types. These are centralized to cut down on circular dependencies
293293
- `cli/`: Code that powers the `astro` CLI command
294294
- `core/`: Code that executes **in the top-level scope** (in Node). Within, you’ll find code that powers the `astro build` and `astro dev` commands, as well as top-level SSR code.
295295
- `runtime/`: Code that executes **in different scopes** (i.e. not in a pure Node context). You’ll have to think about code differently here.

packages/astro/astro-jsx.d.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ declare namespace astroHTML.JSX {
1717
children: {};
1818
}
1919

20-
interface IntrinsicAttributes
21-
extends AstroBuiltinProps,
22-
AstroBuiltinAttributes,
23-
AstroClientDirectives {
20+
interface IntrinsicAttributes extends AstroComponentDirectives, AstroBuiltinAttributes {
2421
slot?: string | undefined | null;
2522
children?: Children;
2623
}
2724

28-
type AstroBuiltinProps = import('./dist/@types/astro.js').AstroBuiltinProps;
29-
type AstroClientDirectives = import('./dist/@types/astro.js').AstroClientDirectives;
30-
type AstroBuiltinAttributes = import('./dist/@types/astro.js').AstroBuiltinAttributes;
31-
type AstroDefineVarsAttribute = import('./dist/@types/astro.js').AstroDefineVarsAttribute;
32-
type AstroScriptAttributes = import('./dist/@types/astro.js').AstroScriptAttributes &
25+
type AstroComponentDirectives =
26+
import('./dist/types/public/elements.js').AstroComponentDirectives;
27+
type AstroBuiltinAttributes = import('./dist/types/public/elements.js').AstroBuiltinAttributes;
28+
type AstroDefineVarsAttribute =
29+
import('./dist/types/public/elements.js').AstroDefineVarsAttribute;
30+
type AstroScriptAttributes = import('./dist/types/public/elements.js').AstroScriptAttributes &
3331
AstroDefineVarsAttribute;
34-
type AstroStyleAttributes = import('./dist/@types/astro.js').AstroStyleAttributes &
32+
type AstroStyleAttributes = import('./dist/types/public/elements.js').AstroStyleAttributes &
3533
AstroDefineVarsAttribute;
36-
type AstroSlotAttributes = import('./dist/@types/astro.js').AstroSlotAttributes;
34+
type AstroSlotAttributes = import('./dist/types/public/elements.js').AstroSlotAttributes;
3735

3836
// This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework
3937
// without importing every single framework's types (which comes with its own set of problems).

packages/astro/client.d.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
/// <reference path="./types/content.d.ts" />
33
/// <reference path="./types/actions.d.ts" />
44

5-
// eslint-disable-next-line @typescript-eslint/no-namespace
6-
declare namespace App {
7-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
8-
export interface Locals {}
9-
}
10-
115
interface ImportMetaEnv {
126
/**
137
* The prefix for Astro-generated asset links if the build.assetsPrefix config option is set. This can be used to create asset links not handled by Astro.
@@ -52,7 +46,7 @@ declare module 'astro:assets' {
5246
getImage: (
5347
options: import('./dist/assets/types.js').UnresolvedImageTransform,
5448
) => Promise<import('./dist/assets/types.js').GetImageResult>;
55-
imageConfig: import('./dist/@types/astro.js').AstroConfig['image'];
49+
imageConfig: import('./dist/types/public/config.js').AstroConfig['image'];
5650
getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService;
5751
inferRemoteSize: typeof import('./dist/assets/utils/index.js').inferRemoteSize;
5852
Image: typeof import('./components/Image.astro').default;
@@ -172,7 +166,7 @@ declare module 'astro:components' {
172166
export * from 'astro/components';
173167
}
174168

175-
type MD = import('./dist/@types/astro.js').MarkdownInstance<Record<string, any>>;
169+
type MD = import('./dist/types/public/content.js').MarkdownInstance<Record<string, any>>;
176170
interface ExportedMarkdownModuleEntities {
177171
frontmatter: MD['frontmatter'];
178172
file: MD['file'];
@@ -191,7 +185,6 @@ declare module '*.md' {
191185
file,
192186
url,
193187
getHeadings,
194-
getHeaders,
195188
Content,
196189
rawContent,
197190
compiledContent,
@@ -206,7 +199,6 @@ declare module '*.markdown' {
206199
file,
207200
url,
208201
getHeadings,
209-
getHeaders,
210202
Content,
211203
rawContent,
212204
compiledContent,
@@ -221,7 +213,6 @@ declare module '*.mkdn' {
221213
file,
222214
url,
223215
getHeadings,
224-
getHeaders,
225216
Content,
226217
rawContent,
227218
compiledContent,
@@ -236,7 +227,6 @@ declare module '*.mkd' {
236227
file,
237228
url,
238229
getHeadings,
239-
getHeaders,
240230
Content,
241231
rawContent,
242232
compiledContent,
@@ -251,7 +241,6 @@ declare module '*.mdwn' {
251241
file,
252242
url,
253243
getHeadings,
254-
getHeaders,
255244
Content,
256245
rawContent,
257246
compiledContent,
@@ -266,7 +255,6 @@ declare module '*.mdown' {
266255
file,
267256
url,
268257
getHeadings,
269-
getHeaders,
270258
Content,
271259
rawContent,
272260
compiledContent,
@@ -275,7 +263,7 @@ declare module '*.mdown' {
275263
}
276264

277265
declare module '*.mdx' {
278-
type MDX = import('./dist/@types/astro.js').MDXInstance<Record<string, any>>;
266+
type MDX = import('./dist/types/public/content.js').MDXInstance<Record<string, any>>;
279267

280268
export const frontmatter: MDX['frontmatter'];
281269
export const file: MDX['file'];
@@ -288,7 +276,7 @@ declare module '*.mdx' {
288276
}
289277

290278
declare module 'astro:ssr-manifest' {
291-
export const manifest: import('./dist/@types/astro.js').SSRManifest;
279+
export const manifest: import('./dist/types/public/internal.js').SSRManifest;
292280
}
293281

294282
// Everything below are Vite's types (apart from image types, which are in `client.d.ts`)

packages/astro/components/Picture.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import { type LocalImageProps, type RemoteImageProps, getImage } from 'astro:assets';
33
import * as mime from 'mrmime';
4-
import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro';
4+
import type { GetImageResult, ImageOutputFormat } from '../dist/types/public/index.js';
55
import { isESMImportedImage, resolveSrc } from '../dist/assets/utils/imageKind';
66
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
77
import type { HTMLAttributes } from '../types';

packages/astro/config.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
type ViteUserConfig = import('vite').UserConfig;
22
type ViteUserConfigFn = import('vite').UserConfigFn;
3-
type AstroUserConfig = import('./dist/@types/astro.js').AstroUserConfig;
4-
type AstroInlineConfig = import('./dist/@types/astro.js').AstroInlineConfig;
5-
type ImageServiceConfig = import('./dist/@types/astro.js').ImageServiceConfig;
3+
type AstroUserConfig = import('./dist/types/public/config.js').AstroUserConfig;
4+
type AstroInlineConfig = import('./dist/types/public/config.js').AstroInlineConfig;
5+
type ImageServiceConfig = import('./dist/types/public/config.js').ImageServiceConfig;
66
type SharpImageServiceConfig = import('./dist/assets/services/sharp.js').SharpImageServiceConfig;
77
type EnvField = typeof import('./dist/env/config.js').envField;
88

@@ -42,4 +42,4 @@ export function passthroughImageService(): ImageServiceConfig;
4242
/**
4343
* Return a valid env field to use in this Astro config for `experimental.env.schema`.
4444
*/
45-
export const envField: EnvField;
45+
export declare const envField: EnvField;

packages/astro/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// As such, if the typings you're trying to add should be available inside ex: React components, they should instead
55
// be inside `client.d.ts`
66

7-
type Astro = import('./dist/@types/astro.js').AstroGlobal;
7+
type Astro = import('./dist/types/public/context.js').AstroGlobal;
88

99
// We have to duplicate the description here because editors won't show the JSDoc comment from the imported type
1010
// However, they will for its properties, ex: Astro.request will show the AstroGlobal.request description

0 commit comments

Comments
 (0)