Skip to content

Conversation

@johnsoncodehk
Copy link
Member

@johnsoncodehk johnsoncodehk commented Dec 14, 2025

Summary

Replace dynamic global types generation with static declaration files to fix Yarn PnP compatibility.

🤖 This summary was written by AI (GitHub Copilot)

Problems with Old Approach

The previous system dynamically generated a global types file at node_modules/.vue-global-types/vue_3.x_xx.d.ts:

  1. Breaks Yarn PnP: Yarn PnP doesn't create node_modules/ directory
  2. Requires file writes: Needs filesystem write permissions
  3. Complex logic: Path resolution, version detection, caching, cleanup

New Approach

How It Works

  1. Static type files shipped with @vue/language-core:

    • types/template-helpers.d.ts - Volar helper types (__VLS_* utilities)
    • types/props-fallback.d.ts - Props fallback when checkUnknownProps: false
    • types/vue-3.4-shims.d.ts - GlobalComponents/GlobalDirectives for Vue < 3.5
  2. Triple-slash directives reference these files in generated code:

/// <reference types="@vue/language-core/types/template-helpers.d.ts" />

TypeScript resolves this through normal package resolution.

  1. Vue-specific types are generated inline using dynamic imports:
import('vue').ShallowUnwrapRef<T>

This is necessary because static files in @vue/language-core/types/ cannot import from the user's Vue package.

Why This Works

  • ✅ Works with all package managers (npm, yarn, pnpm, Yarn PnP, bun)
  • ✅ No file system writes needed
  • ✅ Types are versioned with the package
  • ✅ Simpler architecture

Breaking Changes

Configuration:

  • vueCompilerOptions.globalTypesPath: (fileName) => stringvueCompilerOptions.typesRoot: string
  • Default: "@vue/language-core/types"

Most users never customized this option.

Changes

Removed:

  • lib/codegen/globalTypes.ts - Dynamic generation logic
  • createGlobalTypesWriter() / writeGlobalTypes() functions
  • File write operations to node_modules/

Added:

  • types/template-helpers.d.ts - Helper types
  • types/props-fallback.d.ts - Fallback types
  • types/vue-3.4-shims.d.ts - Vue 3.4 shims

Modified:

  • Generated code uses import('vue').XXX for Vue types
  • All packages updated to remove dynamic type generation

@johnsoncodehk johnsoncodehk marked this pull request as draft December 14, 2025 04:16
@johnsoncodehk johnsoncodehk marked this pull request as ready for review December 14, 2025 04:46
@johnsoncodehk johnsoncodehk merged commit f498667 into master Dec 14, 2025
7 checks passed
@johnsoncodehk johnsoncodehk deleted the static-type-files branch December 14, 2025 05:29
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