Skip to content

fix(types): declare fontsource modules for TypeScript 6 (ts2882) - #710

Merged
prototypa merged 1 commit into
arthelokyo:mainfrom
danfitz36:fix/fontsource-side-effect-import-types
Jun 4, 2026
Merged

fix(types): declare fontsource modules for TypeScript 6 (ts2882)#710
prototypa merged 1 commit into
arthelokyo:mainfrom
danfitz36:fix/fontsource-side-effect-import-types

Conversation

@danfitz36

Copy link
Copy Markdown
Contributor

What

Resolves the ts(2882) error on the fontsource side-effect import in src/components/CustomStyles.astro under TypeScript 6.0 (strict on by default).

Related to #707. Third and final piece of vanilla-template TS 6 readiness, alongside #708 (permalinks.ts) and #709 (blog.ts).

Why

CustomStyles.astro loads the font via a side-effect import:

import '@fontsource-variable/inter';

Fontsource packages ship CSS only — no .d.ts. Under TS 6, a side-effect import of a module with no type declarations is an error:

src/components/CustomStyles.astro:2:8 - error ts(2882): Cannot find module or type declarations for side-effect import of '@fontsource-variable/inter'.

Change

Add ambient module declarations in src/env.d.ts:

declare module '@fontsource-variable/*';
declare module '@fontsource/*';

(Both scopes are declared since the commented-out font options in CustomStyles.astro include non-variable @fontsource/* families.) Purely a type-level shim — Vite still resolves and bundles the CSS, so build output is unchanged.

Verification

With typescript@6, npx astro check no longer reports the ts(2882) error (CustomStyles.astro is clean). eslint and prettier pass.

With #708 and #709 also applied, astro check reports 0 errors on a vanilla AstroWind install under TypeScript 6.

Fontsource packages ship CSS only, so the side-effect import
`import '@fontsource-variable/inter'` in CustomStyles.astro has no type
declarations. Under TypeScript 6 strict, that is an error (ts2882:
cannot find module or type declarations for side-effect import).

Add ambient module declarations for @fontsource-variable/* and
@fontsource/* in env.d.ts. Build behavior is unchanged; Vite still
resolves and bundles the CSS.

Related to arthelokyo#707.
@prototypa
prototypa merged commit 30173c4 into arthelokyo:main Jun 4, 2026
2 checks passed
@prototypa

Copy link
Copy Markdown
Contributor

Thanks @danfitz36

prototypa added a commit that referenced this pull request Aug 4, 2026
…ort-types

fix(types): declare fontsource modules for TypeScript 6 (ts2882)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants