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

オープン
#470 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript, vite

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

问题描述

在 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 的消费者类型检查。

主要言語
TypeScript
スター
109
フォーク
19
平均マージ
1日 21時間
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

opentiny/tiny-robot のほかの issue

opentiny/tiny-robot の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。