Giter Club home page Giter Club logo

Comments (24)

PatrykWalach avatar PatrykWalach commented on April 28, 2024 6

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: {
    }
  })
}

from composition-api.

liximomo avatar liximomo commented on April 28, 2024 4

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

from composition-api.

IlCallo avatar IlCallo commented on April 28, 2024 2

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.

from composition-api.

bigmeow avatar bigmeow commented on April 28, 2024 1

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

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

@liximomo

from composition-api.

LinusBorg avatar LinusBorg commented on April 28, 2024 1

You are welcome to work on solving this challebge.

from composition-api.

jorgy343 avatar jorgy343 commented on April 28, 2024 1

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.

from composition-api.

kevinmarrec avatar kevinmarrec commented on April 28, 2024 1

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

Classic import
image

Lazy loading
image

image

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

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);

from composition-api.

HermitSun avatar HermitSun commented on April 28, 2024

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.

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

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

from composition-api.

HermitSun avatar HermitSun commented on April 28, 2024

I got your point. Thanks a lot.

from composition-api.

bigmeow avatar bigmeow commented on April 28, 2024

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.

from composition-api.

LinusBorg avatar LinusBorg commented on April 28, 2024

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.

from composition-api.

HermitSun avatar HermitSun commented on April 28, 2024

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> 
        };
    }
}

from composition-api.

IlCallo avatar IlCallo commented on April 28, 2024

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?

from composition-api.

PatrykWalach avatar PatrykWalach commented on April 28, 2024

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.

from composition-api.

Mister-Hope avatar Mister-Hope commented on April 28, 2024

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?

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

@jorgy343 It will allow all vue2 options.

from composition-api.

pauloevpr avatar pauloevpr commented on April 28, 2024

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.

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

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

from composition-api.

bigmeow avatar bigmeow commented on April 28, 2024

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

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

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

from composition-api.

liximomo avatar liximomo commented on April 28, 2024

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

from composition-api.

kevinmarrec avatar kevinmarrec commented on April 28, 2024

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

from composition-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.