You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
note: `strict:true` stricter inference for data properties on `this`. If you do not use it, `this` will always be treated as `any`
9
+
1. A good understanding of [Vue.js](https://vuejs.org/)
10
+
2. Read the TypeScript support section in the Vue docs [2.x](https://vuejs.org/v2/guide/typescript.html) | [3.x](https://v3.vuejs.org/guide/typescript-support.html#typescript-support)
11
+
12
+
## Vue + TypeScript Starter Kits
13
+
14
+
1. Using the [Vue CLI](https://vuejs.org/v2/guide/installation.html#CLI) , you can select the [TypeScript plugin](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript) to be setup in a new a Vue project.
15
+
16
+
```bash
17
+
# 1. Install Vue CLI, if it's not already installed
18
+
npm install --global @vue/cli
19
+
20
+
# 2. Create a new project, then choose the "Manually select features" option
21
+
vue create <my-project-name>
22
+
```
23
+
24
+
2.[Vite](https://github.com/vitejs/vite) is a new build tool by Evan You. It currently only works with Vue 3.x but supports TypeScript out-of-the-box.
25
+
26
+
> ⚠ Currently in beta. Do not use in production.
27
+
28
+
```bash
29
+
npm init vite-app <project-name>
30
+
cd<project-name>
31
+
npm install
32
+
npm run dev
33
+
```
34
+
35
+
# Section 2: Getting Started
36
+
37
+
## Recommended `ts.config` setup
38
+
39
+
>note: `strict:true` stricter inference for data properties on `this`. If you do not use it, `this` will always be treated as `any`
10
40
```json
11
41
// tsconfig.json
12
42
{
@@ -19,19 +49,40 @@ note: `strict:true` stricter inference for data properties on `this`. If you do
19
49
}
20
50
```
21
51
22
-
## Usage in .vue files
23
-
add`lang="ts"` to the script tag to declare TS as the lang used.
24
-
```html
52
+
## Usage in `.vue` files
53
+
Add`lang="ts"` to the script tag to declare TS as the `lang` used.
54
+
```js
25
55
<script lang="ts">
26
56
...
27
57
</script>
28
58
```
29
59
30
-
use `defineComponent` to get type inference in Vue component options
60
+
In Vue 2.x you need to define components with `Vue.component` or `Vue.extend`:
61
+
62
+
```js
63
+
<script lang="ts">
64
+
importVuefrom"vue";
65
+
66
+
exportdefaultVue.extend({
67
+
68
+
// type inference enabled
69
+
name:"HelloWorld",
70
+
props: {
71
+
msg:String
72
+
}
73
+
});
74
+
</script>
75
+
```
76
+
77
+
In Vue 3.x you can use `defineComponent` to get type inference in Vue component options
78
+
31
79
```js
32
80
import { defineComponent } from'vue'
33
81
34
82
constComponent=defineComponent({
35
83
// type inference enabled
36
84
})
37
85
```
86
+
87
+
# Other Vue + TypeScript resources
88
+
- Views on Vue podcast - https://devchat.tv/views-on-vue/vov-076-typescript-tell-all-with-jack-koppa/
0 commit comments