Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the components option in createComponent() doesn't support vue2 options #62

Closed
HermitSun opened this issue Aug 16, 2019 · 24 comments
Closed
Labels
bug Something isn't working

Comments

@HermitSun
Copy link

HermitSun commented Aug 16, 2019

After I updated to 2.2.0, I found that when I run npm run serve, the develop server console ouput is just like this:

And I cannot run npm run build, the process will crash because of the error.

However, the browser console didn't show any errors, and it can run normally. So I cannot simply reproduce it online... In fact, I just create the project with vue-cli3, and change App.vue to this:

<script lang="ts">
    import {createComponent} from 'vue-function-api';
    import HelloWorld from './components/HelloWorld.vue';

    export default createComponent({
        components: {HelloWorld}
    });
</script>

I read the RFC again, and maybe 3.x will continue to be compatible with the 2.x components option?

And when I went back to 2.1.2, the type error disappeared. Did I go something wrong? Or how can I import and use *.vue components correctly?

@liximomo
Copy link
Member

liximomo commented Aug 16, 2019

createComponent only support using with an inline render function return by setup now.

import {createComponent, createElement as h } from 'vue-function-api';
import HelloWorld from './components/HelloWorld.vue';

export default createComponent({
  setup() {
     return () => h(HelloWorld)
 }
});

You can make it work by a force-cast as well.

import {createComponent, createElement as h } from 'vue-function-api';
import HelloWorld from './components/HelloWorld.vue';

export default createComponent({
 components: {HelloWorld}
} as any);

@HermitSun HermitSun changed the title the components option in setup() is not working as expect the components option in createComponent() is not working as expect Aug 16, 2019
@HermitSun
Copy link
Author

OK, thank you. I have another question, could I use it along with template? Using render function will override the template.
And I changed the issue's title to avoid misleading.

@liximomo
Copy link
Member

liximomo commented Aug 16, 2019

@HermitSun Yes. You can use it with the template, but it still requests a force-cast for passing components options.

@HermitSun
Copy link
Author

I got your point. Thanks a lot.

@bigmeow
Copy link

bigmeow commented Aug 16, 2019

image
This change is too big, I plan to downgrade the version。
Every time I upgrade to a new version, I have to change the code again.

@bigmeow
Copy link

bigmeow commented Aug 16, 2019

the name option in createComponent() how to dealwith?
Is there any other way besides setting any type?

export default createComponent({
   name: 'componentName'
})

@liximomo

@LinusBorg
Copy link
Member

LinusBorg commented Aug 16, 2019

I think you should not cast the options obect to any when you do provide a setup function. Then TS can correctly infer types for setup() arguments.

@HermitSun
Copy link
Author

HermitSun commented Aug 16, 2019

Maybe we can expand the interface? Just like @PatrykWalach said in issue#63:

import {ComponentOptions} from 'vue-function-api/dist/ts-api/component';
import {AsyncComponent, Component} from 'vue';

declare module 'vue-function-api/dist/ts-api/component' {
    interface ComponentOptions {
        components?: {
            [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> 
        };
    }
}

@PatrykWalach
Copy link

PatrykWalach commented Aug 16, 2019

Casting as any will break all the types support.
One of the workarounds right now is to take all the keys, except props an setup outside the createComponent function.

export default {
  components: {
  },
  ...createComponent({
    setup(props) {
    },
    props: {
    }
  })
}

@IlCallo
Copy link

IlCallo commented Aug 16, 2019

createComponent only support using with an inline render function return by setup now.

Why so? By spec, its not written anywhere that setup() and other properties cannot be used together (especially component and name for which I don't see a clear alternative).
There even is an example of mixed-usage where setup() and data are used together.

@LinusBorg
Copy link
Member

You are welcome to work on solving this challebge.

@IlCallo
Copy link

IlCallo commented Aug 16, 2019

Before trying tackle the problem, I need to understand it in its entirety.
components and name are probably not the only properties which are needed but have been removed from the type, can you provide me some context about this change? Why was it necessary? Why implementing it required dropping those properties and/or not being a Vue instance anymore (if it was such before)? Are the two things related?

@PatrykWalach
Copy link

The properties probably has been removed unintentionally, the options inside createComponent should extend the default vue ComponentOptions. You can see inside /ts-api/component that VueProxy which is result of the function extends ComponentOptions, which means it should return a proper Vue instance. I'm not too familiar with the types inside Vue so I couldn't find a solution, but I think problem is located inside this file.

@Mister-Hope
Copy link
Contributor

Mister-Hope commented Aug 17, 2019

Casting as any will break all the types support.
One of the workarounds right now is to take all the keys, except props an setup outside the createComponent function.

export default {
  components: {
  },
  ...createComponent({
    setup(props) {
    },
    props: {
    }
  })
}

I thought this is a better solution. Yet I still wanna see types contain components option originally.

So why are you removing it actually?

@jorgy343
Copy link

I'm confused. Is the final behavior going to no longer allow name and components properties within the createComponent function? This is important to know so that I can either downgrade the package for the time being or begin migrating to a newer standard.

@liximomo liximomo added the bug Something isn't working label Aug 21, 2019
@liximomo
Copy link
Member

@jorgy343 It will allow all vue2 options.

@liximomo
Copy link
Member

This is already been fixed in dev branch.
https://github.com/vuejs/vue-function-api/blob/703bf300308ff3a550b236cd3de461fcec9f2213/src/component/component.ts#L70-L73

@pauloevpr
Copy link

While the issue is not fixed, I believe that best way to work it around is by temporarily replacing export default createComponent({ }) by export default { }. This will break Typescript inference but it will not break compilation. If using props, you might also need to go with setup(props: any) {}.

It should be fairly quick to rollback to using createComponent once the issue is fixed.

@kevinmarrec
Copy link

kevinmarrec commented Aug 24, 2019

@liximomo Seems that on @vue/composition-api 0.1., components work BUT not for lazy ones :

Classic import
image

Lazy loading
image

image

@liximomo
Copy link
Member

@kevinmarrec I couldn't reproduce it. Can you provide an online example?

@bigmeow
Copy link

bigmeow commented Aug 25, 2019

This is already been fixed in dev branch.
https://github.com/vuejs/vue-function-api/blob/703bf300308ff3a550b236cd3de461fcec9f2213/src/component/component.ts#L70-L73

Can you release a version as soon as possible? 2.2.1 for vue-function-api

@liximomo
Copy link
Member

@bigmeow The package has been rename to @vue/composition-api.

@liximomo
Copy link
Member

This already got fixed in the new package @vue/composition-api.

@liximomo liximomo changed the title the components option in createComponent() is not working as expect the components option in createComponent() is not support vue2 options Aug 25, 2019
@liximomo liximomo changed the title the components option in createComponent() is not support vue2 options the components option in createComponent() don't supports vue2 options Aug 25, 2019
@liximomo liximomo changed the title the components option in createComponent() don't supports vue2 options the components option in createComponent() doesn't support vue2 options Aug 25, 2019
@kevinmarrec
Copy link

kevinmarrec commented Aug 25, 2019

@liximomo About #62 (comment), I opened #81 with reproduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants