Skip to content

Commit

Permalink
docs: update simple example for use
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Oct 19, 2021
1 parent 459b8d6 commit 89384f4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
33 changes: 33 additions & 0 deletions README.md
Expand Up @@ -12,6 +12,8 @@ yarn add vite-plugin-dts -D

## Usage

In `vite.config.ts`:

```ts
import { resolve } from 'path'
import { defineConfig } from 'vite'
Expand All @@ -30,6 +32,37 @@ export default defineConfig({
})
```

In your component:

```vue
<template>
<div></div>
</template>
<script lang="ts">
// using defineComponent for inferring types
import { defineComponent } from 'vue'
export default defineComponent({
name: 'Component'
})
</script>
```

```vue
<script setup lang="ts">
// Need to access the defineProps returned value to
// infer types although you never use the props directly
const props = defineProps<{
color: 'blue' | 'red'
}>()
</script>
<template>
<div>{{ color }}</div>
</template>
```

## Options

```ts
Expand Down
32 changes: 32 additions & 0 deletions README.zh-CN.md
Expand Up @@ -12,6 +12,8 @@ yarn add vite-plugin-dts -D

## 使用

`vite.config.ts`:

```ts
import { resolve } from 'path'
import { defineConfig } from 'vite'
Expand All @@ -30,6 +32,36 @@ export default defineConfig({
})
```

在你的组件中:

```vue
<template>
<div></div>
</template>
<script lang="ts">
// 使用 defineComponent 来进行类型推断
import { defineComponent } from 'vue'
export default defineComponent({
name: 'Component'
})
</script>
```

```vue
<script setup lang="ts">
// 尽管没有直接使用 props,你仍需要接收 defineProps 的返回值
const props = defineProps<{
color: 'blue' | 'red'
}>()
</script>
<template>
<div>{{ color }}</div>
</template>
```

## 选项

```ts
Expand Down
5 changes: 2 additions & 3 deletions example/components/JsTest.vue
Expand Up @@ -5,9 +5,8 @@
</template>

<script>
// 尽管在使用 js 语法
// 如果仍想要获得正确的类型推导
// 依然需要使用 defineComponent 定义组件
// If you still want to ge the currect types inference with using
// js syntax, you need using defineComponent to define component
import { defineComponent, ref } from 'vue'
export default defineComponent({
Expand Down
5 changes: 2 additions & 3 deletions example/components/JsxTest.jsx
@@ -1,6 +1,5 @@
// 尽管在使用 jsx 语法
// 如果仍想要获得正确的类型推导
// 依然需要使用 defineComponent 定义组件
// If you still want to ge the currect types inference with using
// js syntax, you need using defineComponent to define component
import { defineComponent } from 'vue'

export default defineComponent({
Expand Down

0 comments on commit 89384f4

Please sign in to comment.