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
- Install
typescript-yaml-plugin and configure it in tsconfig.json.
- Create a data file:
src/data/test.yml with some structured properties.
- Create a TypeScript file:
src/utils/test.ts and import the YAML file. Hovering over the import shows the parsed type layout perfectly.
- Create an Astro component:
src/components/Test.astro.
- 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:
-
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"]
}
-
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.
When using
typescript-yaml-pluginin an Astro project, YAML imports are beautifully, strictly typed inside native.tsand.jsfiles. However, when importing the exact same YAML files inside the frontmatter script block of an.astrocomponent, the type inference completely breaks and falls back toany.To Reproduce
typescript-yaml-pluginand configure it intsconfig.json.src/data/test.ymlwith some structured properties.src/utils/test.tsand import the YAML file. Hovering over the import shows the parsed type layout perfectly.src/components/Test.astro.Expected behavior
The type definitions interceptor should consistently infer the type of the YAML file inside
.astrofiles, matching the behavior seen in native.tsenvironments.Context / Technical Root Cause
The issue stems from how the VS Code Astro Language Server (
withastro/language-tools) handles script extraction.When parsing
.astrocomponents, it boots an isolated virtual TypeScript engine to evaluate the frontmatter. During this phase, it reads base compiler options fromtsconfig.jsonbut does not evaluate or forward the third-partypluginsarray to its custom language service host. Because your plugin initializes via the standardts.server.PluginCreateInfolifecycle 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:
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"] }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 standardtsconfigplugin architectures.Environment
typescript-yaml-pluginversion: 1.0.11typescriptversion: 5.9.3astroversion: 6.2.2