Skip to content

fix: inject Astro global types into TS programs#2983

Open
kovsu wants to merge 2 commits into
flint-fyi:mainfrom
kovsu:fix/astro-global-types
Open

fix: inject Astro global types into TS programs#2983
kovsu wants to merge 2 commits into
flint-fyi:mainfrom
kovsu:fix/astro-global-types

Conversation

@kovsu

@kovsu kovsu commented Jun 16, 2026

Copy link
Copy Markdown
Member

PR Checklist

  • Addresses an existing open issue: N/A — no open issue for this Astro language diagnostic fix.
  • That issue was marked as status: accepting prs: N/A — no issue.
  • Steps in CONTRIBUTING.md were taken.

Overview

Adds Astro's global type declarations to TypeScript programs that contain .astro roots, matching Astro language-server's program-level type injection instead of patching generated virtual TSX.

Verification run locally: pnpm --filter=@flint.fyi/astro-language test, pnpm build, pnpm lint, pnpm flint, pnpm lint:knip, pnpm lint:knip:prod, and pnpm dedupe --check --prefer-offline.

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5097576

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

Deploy Preview for flint-fyi ready!

Name Link
🔨 Latest commit 5097576
🔍 Latest deploy log https://app.netlify.com/projects/flint-fyi/deploys/6a31913a62306e0008ef3989
😎 Deploy Preview https://deploy-preview-2983--flint-fyi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! But I'm not particularly familiar with Astro globals / Volar, and would want a second opinion for sure.

astro: {
ast,
// Astro's language server injects these same type files through getScriptFileNames:
// https://github.com/withastro/astro/blob/main/packages/language-tools/language-server/src/core/index.ts#L31-L74

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Docs] To make this a permalink ~

Suggested change
// https://github.com/withastro/astro/blob/main/packages/language-tools/language-server/src/core/index.ts#L31-L74
// https://github.com/withastro/astro/blob/c0f33eda8adf6f8f2588688f6205b76a96a42466/packages/language-tools/language-server/src/core/index.ts#L31-L74

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval One team member approved; we're now waiting for a second approval or for 2 business days to pass. label Jun 17, 2026
// Astro's language server injects these same type files through getScriptFileNames:
// https://github.com/withastro/astro/blob/main/packages/language-tools/language-server/src/core/index.ts#L31-L74
function addAstroTypes(
ts: typeof import("typescript"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend naming this something else or using named imports at the top of the file (my preference). ts is already declared in the module scope, and having it named the same here can be confusing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auvred and I have bikeshedden this a lot, we don't really see a better option because of TS's shadowing rules. But, @michaelfaith, please give it a test and if you can find a version that works, file an issue/PR to make them consistent.

Sorry if that feels short, long day.

@michaelfaith michaelfaith Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand that. Wouldn't a better option be what I suggested: using named imports at the top instead of a default import named ts? Or the other suggestion I said, which is changing the name of this parameter to something else (e.g. typescript) so it doesn't "shadow" the default import ts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you're saying 👍🏻

I was thinking about replacing the typeof import("typescript") but that works as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to leave for now though, this is how all of the adapters are shaped. If you want it changed, might as well do it everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 approval One team member approved; we're now waiting for a second approval or for 2 business days to pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants