Enable TypeScript language server features (error checking, type checking, IntelliSense) for TypeScript code embedded in YAML files - similar to how it works in Markdown files!
- ✅ Type Checking: Get TypeScript errors directly in your YAML files
- ✅ IntelliSense: Auto-completion and hover information for TypeScript code
- ✅ Diagnostics: See TypeScript errors, warnings, and suggestions inline
- ✅ Automatic Detection: Automatically detects TypeScript code blocks in YAML files
- ✅ Real-time Updates: Diagnostics update as you type
The extension uses Virtual Documents to extract TypeScript code from YAML files and connect it to the TypeScript language server. This is the same approach used by VS Code for Markdown files.
When you open a YAML file:
- The extension scans for TypeScript code blocks
- Each code block is extracted and registered as a virtual
.tsdocument - The TypeScript language server analyzes the virtual documents
- Diagnostics (errors, warnings) are mapped back to the original YAML file
- You see TypeScript errors directly in your YAML file!
Simply write TypeScript code in your YAML files using multiline string blocks. The extension will automatically detect and analyze TypeScript code in values with keys like:
code,script,handler,transform, etc.- Any multiline string that looks like TypeScript
name: My Configuration
# TypeScript code with type checking
handler:
code: |
interface User {
id: number;
name: string;
email: string;
}
const user: User = {
id: 1,
name: "John",
// ERROR: Missing 'email' property
};
# Function with generics
utils:
script: |
function processData<T>(data: T[]): T[] {
return data.filter(item => item !== null);
}
// ERROR: Type '"invalid"' is not assignable
type Status = "active" | "inactive";
const status: Status = "invalid";The extension detects TypeScript code in several ways:
-
Explicit Markers: Use comments to mark TypeScript blocks
# typescript: code: | const x: number = 1;
-
Common Keys: Keys containing
code,script,handler,transform, etc.script: | function hello() { }
-
Heuristic Detection: Automatically detects TypeScript patterns
const,let,var,function,class,interface,type- Type annotations (
: string,: number, etc.) - Arrow functions (
=>) - Imports/exports
- Generics (
<T>)
- VS Code 1.105.0 or higher
- TypeScript installed in your workspace or globally
YAMLScript: Hello World- Test command to verify the extension is active
- Line/column mappings may be slightly off for deeply indented code blocks
- Some advanced TypeScript features may not work perfectly in all contexts
- The extension works best with isolated code blocks (not split across multiple YAML values)
This extension brings the same TypeScript integration that Markdown files have to YAML files:
| Feature | Markdown Code Blocks | YAML with YAMLScript |
|---|---|---|
| TypeScript Errors | ✅ | ✅ |
| Type Checking | ✅ | ✅ |
| IntelliSense | ✅ | ✅ |
| Real-time Updates | ✅ | ✅ |
| Diagnostics | ✅ | ✅ |
To work on this extension:
# Install dependencies
pnpm install
# Compile and watch for changes
pnpm run watch
# Run the extension in debug mode
# Press F5 in VS Code- Open the extension folder in VS Code
- Press
F5to launch the Extension Development Host - Open the
example.yamlfile - You should see TypeScript errors highlighted in the YAML file!
Initial release:
- Virtual document provider for TypeScript code in YAML
- Automatic code block detection
- TypeScript diagnostics mapped to YAML source
- Support for multiple code blocks per file
Found a bug or have a feature request? Please open an issue on GitHub!
Enjoy coding with TypeScript in YAML! 🚀