Skip to content

Compatible with tsconfig allowArbitraryExtensions option #13295

@Teages

Description

@Teages

Vue version

3.5.13

Link to minimal reproduction

https://github.com/Teages/vue-allow-arbitrary-extensions

Steps to reproduce

  1. enable allowArbitraryExtensions in tsconfig.json
  2. create two files: WithType.vue, WithType.d.vue.ts, add a type export in WithType.d.vue.ts
  3. try to import the type by import type { X } from './WithType.vue'

You can run pnpm i & pnpm play in the reproduction

What is expected?

Vue should load the type from WithType.d.vue.ts as allowArbitraryExtensions was enable and .vue file is not a known JavaScript or TypeScript file extension.

What is actually happening?

Vue try to resolve the type from WithType.vue but not WithType.d.vue.ts, and finally it doesn't find the type and throw a error:

~/main.ts:80
      throw new Error(`[vue-sfc-transformer] ${msg}`);
            ^

Error: [vue-sfc-transformer] Unresolvable type reference or unsupported built-in utility type
    at Object.error (~/main.ts:80:13)
    at innerResolveTypeElements (~/node_modules/.pnpm/@vue+compiler-sfc@3.5.13/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:22104:20)
    at resolveTypeElements (~/node_modules/.pnpm/@vue+compiler-sfc@3.5.13/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:21995:20)
    at resolveRuntimePropsFromType (~/node_modules/.pnpm/@vue+compiler-sfc@3.5.13/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:23632:20)
    at extractRuntimeProps (~/node_modules/.pnpm/@vue+compiler-sfc@3.5.13/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js:23608:17)
    at processDefineProps (~/main.ts:57:57)
    at ~/main.ts:24:35

Node.js v22.14.0

System Info

N/A

Any additional comments?

nuxt/module-builder#597
unjs/mkdist#270
unjs/mkdist#268 (comment)
https://github.com/vuejs/core/blob/v3.5.13/packages/compiler-sfc/src/script/resolveType.ts#L1154

microsoft/TypeScript#50133

I can try to make a pull request to fix it if you want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.scope: compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions