Skip to content

Commit

Permalink
chore: collapse legacy FAQs
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Nov 30, 2023
1 parent f70e5fc commit 6b9d94c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ Starting with `3.0.0`, you can use this plugin with Rollup.

Here are some FAQ's and solutions.

### Missing some declaration files after build (before `1.7.0`)

By default, the `skipDiagnostics` option is set to `true` which means type diagnostics will be skipped during the build process (some projects may have diagnostic tools such as `vue-tsc`). Files with type errors which interrupt the build process will not be emitted (declaration files won't be generated).

If your project doesn't use type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on diagnostic and logging features of this plugin. Type errors during build will be logged to the terminal.

### Type error when using both `script` and `setup-script` in Vue component (before `3.0.0`)

This is usually caused by using the `defineComponent` function in both `script` and `setup-script`. When `vue/compiler-sfc` compiles these files, the default export result from `script` gets merged with the parameter object of `defineComponent` from `setup-script`. This is incompatible with parameters and types returned from `defineComponent`. This results in a type error.

Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue). You should remove the `defineComponent` in `script` and export a native object directly.

### Type errors that are unable to infer types from packages in `node_modules`

This is an existing [TypeScript issue](https://github.com/microsoft/TypeScript/issues/42873) where TypeScript infers types from packages located in `node_modules` through soft links (pnpm). A workaround is to add `baseUrl` to your `tsconfig.json` and specify the `paths` for these packages:
Expand All @@ -96,6 +84,23 @@ For example: `baseUrl: 'src'` is specified and importing from `<root>/src/compon

Currently, you need to avoid the above situation, or use aliases instead (with the `paths` option).

<details>
<summary>Legacy</summary>

### Missing some declaration files after build (before `1.7.0`)

By default, the `skipDiagnostics` option is set to `true` which means type diagnostics will be skipped during the build process (some projects may have diagnostic tools such as `vue-tsc`). Files with type errors which interrupt the build process will not be emitted (declaration files won't be generated).

If your project doesn't use type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on diagnostic and logging features of this plugin. Type errors during build will be logged to the terminal.

### Type error when using both `script` and `setup-script` in Vue component (before `3.0.0`)

This is usually caused by using the `defineComponent` function in both `script` and `setup-script`. When `vue/compiler-sfc` compiles these files, the default export result from `script` gets merged with the parameter object of `defineComponent` from `setup-script`. This is incompatible with parameters and types returned from `defineComponent`. This results in a type error.

Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue). You should remove the `defineComponent` in `script` and export a native object directly.

</details>

## Options

```ts
Expand Down
29 changes: 17 additions & 12 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ export default defineConfig({

此处将收录一些常见的问题并提供一些解决方案。

### 打包后出现类型文件缺失 (`1.7.0` 之前)

默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。

如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false``logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。

### Vue 组件中同时使用了 `script``setup-script` 后出现类型错误(`3.0.0` 之前)

这通常是由于分别在 `script``setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script``defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。

这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。

### 打包时出现了无法从 `node_modules` 的包中推断类型的错误

这是 TypeScript 通过软链接 (pnpm) 读取 `node_modules` 中过的类型时会出现的一个已知的问题,可以参考这个 [issue](https://github.com/microsoft/TypeScript/issues/42873),目前已有的一个解决方案,在你的 `tsconfig.json` 中添加 `baseUrl` 以及在 `paths` 添加这些包的路径:
Expand All @@ -96,6 +84,23 @@ export default defineConfig({

目前想要正常打包,需要规避上述情况,或使用别名代替(配合 `paths` 属性)。

<details>
<summary>过时的</summary>

### 打包后出现类型文件缺失 (`1.7.0` 之前)

默认情况下 `skipDiagnostics` 选项的值为 `true`,这意味着打包过程中将跳过类型检查(一些项目通常有 `vue-tsc` 等的类型检查工具),这时如果出现存在类型错误的文件,并且这是错误会中断打包过程,那么这些文件对应的类型文件将不会被生成。

如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false``logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。

### Vue 组件中同时使用了 `script``setup-script` 后出现类型错误(`3.0.0` 之前)

这通常是由于分别在 `script``setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script``defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。

这是一个简单的[示例](https://github.com/qmhc/vite-plugin-dts/blob/main/example/components/BothScripts.vue),您应该将位于 `script` 中的 `defineComponent` 方法移除,直接导出一个原始的对象。

</details>

## 选项

```ts
Expand Down

0 comments on commit 6b9d94c

Please sign in to comment.