Skip to content

Plugin types evaluate to any inside .astro files (Astro Language Server compatibility) #5

Description

@Stephcraft

When using typescript-yaml-plugin in an Astro project, YAML imports are beautifully, strictly typed inside native .ts and .js files. However, when importing the exact same YAML files inside the frontmatter script block of an .astro component, the type inference completely breaks and falls back to any.

To Reproduce

  1. Install typescript-yaml-plugin and configure it in tsconfig.json.
  2. Create a data file: src/data/test.yml with some structured properties.
  3. Create a TypeScript file: src/utils/test.ts and import the YAML file. Hovering over the import shows the parsed type layout perfectly.
  4. Create an Astro component: src/components/Test.astro.
  5. Import the same YAML file in the frontmatter:
---
import data from '../data/test.yml';
// Hovering over 'data' shows it as type 'any'
---

Expected behavior

The type definitions interceptor should consistently infer the type of the YAML file inside .astro files, matching the behavior seen in native .ts environments.

Context / Technical Root Cause

The issue stems from how the VS Code Astro Language Server (withastro/language-tools) handles script extraction.

When parsing .astro components, it boots an isolated virtual TypeScript engine to evaluate the frontmatter. During this phase, it reads base compiler options from tsconfig.json but does not evaluate or forward the third-party plugins array to its custom language service host. Because your plugin initializes via the standard ts.server.PluginCreateInfo lifecycle hook, it is entirely skipped by Astro's language server setup.

Possible Solutions / Feature Request

Since this is a systemic issue with how language server wrappers isolate script execution layers, it can be approached in two ways:

  1. Documentation Update: Add a note to the README explaining how to force global resolution in editors like VS Code for mixed-framework setups using workspace settings:

    {
      "typescript.tsserver.pluginPaths": ["./node_modules"]
    }
  2. Expose a Core Helper: Export an internal type-parsing method or standalone script runner that can be explicitly fed into global ambient declarations (env.d.ts) as a fallback for custom compilers that bypass standard tsconfig plugin architectures.

Environment

  • typescript-yaml-plugin version: 1.0.11
  • typescript version: 5.9.3
  • astro version: 6.2.2
  • IDE: VS Code with official Astro extension installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions