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
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
+
## React + 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. Which current only works with Vue 3.x but works with TypeScript out-of-the-box.
25
+
26
+
> ⚠ Current in beta. Don't 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
7
38
8
-
## Recommended ts.config setup
9
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
@@ -19,19 +49,38 @@ 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
+
```vue
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
31
-
```js
60
+
In Vue 2.x you need to define components with `Vue.component` or `Vue.extend`:
61
+
62
+
```vue
63
+
<script lang="ts">
64
+
import Vue from "vue";
65
+
66
+
export default Vue.extend({
67
+
name: "HelloWorld",
68
+
props: {
69
+
msg: String
70
+
}
71
+
});
72
+
</script>
73
+
```
74
+
75
+
In Vue 3.x you can use `defineComponent` to get type inference in Vue component options
76
+
77
+
```vue
32
78
import { defineComponent } from 'vue'
33
79
34
80
const Component = defineComponent({
35
81
// type inference enabled
36
82
})
37
83
```
84
+
85
+
# Other Vue + TypeScript resources
86
+
- Views on Vue podcast - https://devchat.tv/views-on-vue/vov-076-typescript-tell-all-with-jack-koppa/
0 commit comments