[Bug]: 0.5.1 主入口声明在 Vue/Vite 项目中关闭 skipLibCheck 后类型检查失败

Aperta
#470 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript, vite

Direzione di ricerca

Start with the reported errors in dist/index.d.ts and trace them back through the declaration-generation and packaging configuration. Reproduce with the provided package.json and tsconfig.json, then run pnpm typecheck; done means the published main entry type-checks with skipLibCheck: false and a consumer test imports Vue components from that entry point.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

问题描述

在 Vue 3 + Vite 的 TypeScript 项目中,从 @opentiny/[email protected] 主入口导入组件,关闭 skipLibCheck 后,vue-tsc 会在包内 dist/index.d.ts 报错。

使用的是常规 module: "ESNext"、moduleResolution: "bundler" 配置,不涉及 NodeNext。以下示例消费 npm 已发布的 0.5.1,不依赖源码仓库或未发布的 PR 构建。

最小复现

创建以下文件:

package.json
{
  "name": "tiny-robot-types-repro",
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite",
    "typecheck": "vue-tsc --noEmit",
    "typecheck:skip": "vue-tsc --noEmit --skipLibCheck"
  },
  "dependencies": {
    "@opentiny/tiny-robot": "0.5.1",
    "vue": "3.5.44",
    "dompurify": "3.4.17",
    "markdown-it": "14.3.3"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "4.6.2",
    "vite": "5.4.21",
    "typescript": "5.8.3",
    "vue-tsc": "3.3.13"
  }
}
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "lib": [
      "ES2022",
      "DOM",
      "DOM.Iterable"
    ],
    "strict": true,
    "skipLibCheck": false,
    "noEmit": true,
    "types": []
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.vue"
  ]
}
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({ plugins: [vue()] })
index.html
<!doctype html>
<html>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>
src/main.ts
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
src/App.vue
<script setup lang="ts">
import { TrAnchor, type AnchorItem } from '@opentiny/tiny-robot'

const items: AnchorItem[] = [{ id: 'intro', label: '简介' }]
</script>

<template>
  <TrAnchor :items="items" />
</template>

在该目录执行:

pnpm install
pnpm typecheck
实际结果

类型检查退出码为 2。主入口声明中的代表性错误如下(路径简写为包内相对路径):

dist/index.d.ts(161,83): error TS2300: Duplicate identifier 'event'.
dist/index.d.ts(197,20): error TS2344: Type 'GlobalComponents' does not satisfy the constraint 'Record<string, Component<...>>'.
dist/index.d.ts(215,12): error TS2749: 'nextTick' refers to a value, but is being used as a type here. Did you mean 'typeof nextTick'?
dist/index.d.ts(5497,44): error TS2304: Cannot find name 'MentionAttrs'.
dist/index.d.ts(5522,45): error TS2304: Cannot find name 'TemplateAttrs'.
dist/index.d.ts(5530,51): error TS2304: Cannot find name 'TemplateSelectAttrs'.

其中 TS2344 的泛型约束用 ... 省略了冗长参数。依赖链还可能报告其他环境类型错误;这里列出的错误均位于 tiny-robot 自身的主入口声明。

对照执行:

pnpm typecheck:skip

本示例可通过。执行 pnpm dev 也可以启动页面,因为 Vite 本身不执行完整的 TypeScript 类型检查。

预期结果

主入口发布的声明应在支持的 Vue 项目中通过类型检查,无需依赖 skipLibCheck: true 隐藏包内声明错误。

验证版本
  • @opentiny/tiny-robot:0.5.1
  • Vue:3.5.44
  • TypeScript:5.8.3
  • vue-tsc:3.3.13
  • Vite:5.4.21
  • @vitejs/plugin-vue:4.6.2

希望检查声明生成/打包结果,并增加一个从发布产物主入口导入 Vue 组件、关闭 skipLibCheck 的消费者类型检查。

Lingua principale
TypeScript
Stelle
109
Fork
19
Merge medio
1g 21h
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di opentiny/tiny-robot

Tutte le issue di opentiny/tiny-robot

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.