File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -141,3 +141,39 @@ var vm = new Vue({
141
141
myOption: ' Hello'
142
142
})
143
143
```
144
+
145
+ ## Annotating Return Types
146
+
147
+ Because of the circular nature of Vue's declaration files, TypeScript may have difficulties inferring the types of certain methods.
148
+ For this reason, you may need to annotate the return type on methods like ` render ` and those in ` computed ` .
149
+
150
+ ``` ts
151
+ import Vue , { VNode } from ' vue'
152
+
153
+ const Component = Vue .extend ({
154
+ data() {
155
+ return {
156
+ msg: ' Hello'
157
+ }
158
+ },
159
+ methods: {
160
+ // need annotation due to `this` in return type
161
+ greet(): string {
162
+ return this .msg + ' world'
163
+ }
164
+ },
165
+ computed: {
166
+ // need annotation
167
+ greeting(): string {
168
+ return this .greet () + ' !'
169
+ }
170
+ },
171
+ // `createElement` is inferred, but `render` needs return type
172
+ render(createElement ): VNode {
173
+ return createElement (' div' , this .greeting )
174
+ }
175
+ })
176
+ ```
177
+
178
+ If you find type inference or member completion isn't working, annotating certain methods may help address these problems.
179
+ Using the ` --noImplicitAny ` option will help find many of these unannotated methods.
You can’t perform that action at this time.
0 commit comments