Composition-api: Missing Typescript examples?

Created on 7 Aug 2019  路  8Comments  路  Source: vuejs/composition-api

Type Inference was a major motivation behind the Function-API. Surprisingly, I can't seem to find examples or even mentions to Typescript support in the README.md. Only the Function-API RFC seems to cover Typescript support.

Most helpful comment

@pauloevpr looks like the readme has a Typescript section now

https://github.com/vuejs/vue-function-api#typescript

All 8 comments

It works out of the box, pretty much everything is automatically or explicitly inferred because of how the api is designed. What were you expecting exactly?

I was expecting to see Typescript-specific examples, such as the ones in the RFC using createComponent() and showing how type inference works with props.

Everyone who's been following the RFCs pretty much knows that the Function-API supports Typescript naturally. But it would be great to make things more explicit especially for developers getting started with the new API.

I really want this epic API to take off.

Yeah, I think having docs in js makes it easy for both javascript and typescript developers to pick it up. Did you find any blocker when using typescript? Something that didn't work out of the box?

Typescript only works properly for me when using createComponent.

image

image

@pauloevpr you can use Vue.extend() to let TypeScript properly infer types inside Vue component options

https://vuejs.org/v2/guide/typescript.html#Basic-Usage

I am not sure if I got your point. We are discussing about the new Function-API. According to the RFC:

"createComponent is conceptually similar to 2.x's Vue.extend, but it is a no-op and only needed for typing purposes."

So createComponent must be used instead of Vue.extend.

I opened this issue to report that the READ.me on this repo lacks Typescript examples. That is all.

@pauloevpr looks like the readme has a Typescript section now

https://github.com/vuejs/vue-function-api#typescript

Great. I am happy now. Thanks.

Was this page helpful?
0 / 5 - 0 ratings