Skip to content

Commit 977b91c

Browse files
committed
Formatting & initial setup for Setup and Getting Started sections.
1 parent 11e60c5 commit 977b91c

File tree

1 file changed

+57
-8
lines changed

1 file changed

+57
-8
lines changed

README.md

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
1-
# vue-typescript-cheatsheet
1+
# Vue+TypeScript Cheatsheets
22

33
Cheatsheets for experienced Vue developers getting started with TypeScript
44

5-
- https://devchat.tv/views-on-vue/vov-076-typescript-tell-all-with-jack-koppa/
5+
# Section 1: Setup
66

7+
## Prerequisites
8+
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+
## 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
738

8-
## Recommended ts.config setup
939
note: `strict:true` stricter inference for data properties on `this`. If you do not use it, `this` will always be treated as `any`
1040
```json
1141
// tsconfig.json
@@ -19,19 +49,38 @@ note: `strict:true` stricter inference for data properties on `this`. If you do
1949
}
2050
```
2151

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
2555
<script lang="ts">
2656
...
2757
</script>
2858
```
2959

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
3278
import { defineComponent } from 'vue'
3379
3480
const Component = defineComponent({
3581
// type inference enabled
3682
})
3783
```
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy