Thanks to visit codestin.com
Credit goes to github.com

Skip to content

when the object type exposed by defineExpose contains an internal declaration, vue-tsc throws an error (当 defineExpose 暴露的对象类型含有内部声明时,vue-tsc 会抛错) #5524

@onlymisaky

Description

@onlymisaky

Vue - Official extension or vue-tsc version

vue-tsc: 3.0.1

VSCode version

1.102.1 (Universal)

Vue version

3.5.17

TypeScript version

5.8.3

package.json dependencies

{
  "dependencies": {
    "vue": "^3.5.17"
  },
  "devDependencies": {
    "typescript": "~5.8.3",
    "vue-tsc": "^3.0.1"
  }
}

Steps to reproduce

because the Ref uses the internal declaration 'RefSymbol', it causes a defineExpose error

由于 Ref 使用了内部声明 RefSymbol , 导致 defineExpose 报错

<script setup lang="ts">
import type { Ref } from 'vue'

defineExpose({  } as Ref<any>);
</script>

because the TemplateRef uses the internal declaration 'ShallowRefMarker', it causes a defineExpose error

由于 TemplateRef 使用了内部声明 ShallowRefMarker , 导致 defineExpose 报错

<script setup lang="ts">
import type { TemplateRef } from 'vue'

defineExpose({} as TemplateRef<any>);
</script>
{
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.tsbuildinfo",
    "composite": true,
    "moduleResolution": "bundler",
    "module": "ESNext",
    "lib": [
      "ES2020",
      "DOM",
      "DOM.Iterable"
    ],
    "allowImportingTsExtensions": true,
    "noEmit": true,
  },
}

even using jsdoc for type annotation will cause errors. since the error message is the same and complicated to reproduce, it was not added

甚至使用 jsdoc 做类型标注也会导致错误。由于错误信息是相同的,而且复现起来比较复杂,所以没有添加进去,

What is expected?

it just uses type derivation, but it causes a vue-tsc error

仅仅是使用了类型推导,但是却导致了 vue-tsc 报错

What is actually happening?

although internal declarations are used, this should not cause vue-tsc to run incorrectly, which is counterintuitive

虽然使用了内部声明,但这不应该导致 vue-tsc 运行出错,这很违反直觉

Link to minimal reproduction

https://github.com/onlymisaky/bug-report-vue-tsc

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions