Vue: Typescript declaration not working with render function

Created on 26 Oct 2017  ·  2Comments  ·  Source: vuejs/vue

Version

2.5.2

Reproduction link

https://github.com/jiayexie/vue-typescript-declaration-repro

Steps to reproduce

  1. Build the project with npm run build. Build should pass.
    image

  2. Uncomment the render function in error.ts and build again. Build fails because component type has changed and only has a 'message' prop on it.
    image

What is expected?

Component type should be inferred from data, props, computed, methods, and be accessible in methods and render functions.

What is actually happening?

As soon as I add a render function, the type inference loses everything except props.

typescript

Most helpful comment

This is because this type inference goes cyclic. Adding VNode return type to your render function would fix the problem.

import Vue, { VNode } from 'vue'

Vue.extend({
  // ...
  render(h): VNode {
    return h('div', this.message)
  }
})

We will include this caveats in the docs.

All 2 comments

This is because this type inference goes cyclic. Adding VNode return type to your render function would fix the problem.

import Vue, { VNode } from 'vue'

Vue.extend({
  // ...
  render(h): VNode {
    return h('div', this.message)
  }
})

We will include this caveats in the docs.

I will make a pull request to vuejs.org.

Was this page helpful?
0 / 5 - 0 ratings