Comments (24)
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.
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.
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.
the name
option in createComponent() how to dealwith?
Is there any other way besides setting any
type?
export default createComponent({
name: 'componentName'
})
from composition-api.
You are welcome to work on solving this challebge.
from composition-api.
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.
@liximomo Seems that on @vue/composition-api
0.1., components
work BUT not for lazy ones :
from composition-api.
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.
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.
@HermitSun Yes. You can use it with the template, but it still requests a force-cast for passing components
options.
from composition-api.
I got your point. Thanks a lot.
from composition-api.
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.
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.
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.
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.
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.
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 thecreateComponent
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.
@jorgy343 It will allow all vue2 options.
from composition-api.
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.
@kevinmarrec I couldn't reproduce it. Can you provide an online example?
from composition-api.
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.
@bigmeow The package has been rename to @vue/composition-api.
from composition-api.
This already got fixed in the new package @vue/composition-api
.
from composition-api.
@liximomo About #62 (comment), I opened #81 with reproduction
from composition-api.
Related Issues (20)
- Bad derivation of type by `ExtractPropTypes` HOT 1
- Typing component refs HOT 2
- onMounted is called when there is no active component instance to be associated with HOT 7
- Variables created with ref in <templete>,do not automatically expand value HOT 4
- why setup run twice in vue2 HOT 8
- setup function provide a wrong prop type,when use type: Function HOT 3
- not work nice in web component, no error HOT 2
- How to avoid duplicate register composition-api ? HOT 1
- It doesn't work with nuxt 2 HOT 2
- watch 的回调如果发生错误,会一直触发调用 HOT 1
- ComponentRenderProxy类型与Vue不兼容,导致Ts编译报错 HOT 2
- vue2项目, 怎么在option API的基础上, 混用composition API? HOT 1
- render 函数中使用 web components 自定义标签,移除了HTML中原生的 slot 属性 HOT 3
- No support for Vue >= 2.7
- cdn方式引入导致vue devtools调试数据丢失 HOT 2
- 客户端使用vuecli 打包出来的commonjs模式的库,出现“Error: [vue-composition-api] must call Vue.use(VueCompositionAPI) before using any functio” HOT 2
- setup返回的data在development环境下会被expose到全局mixin的data中 HOT 2
- 是否有提供withDefaults?
- 安装时,报vue版本范围错误 HOT 2
- 【Bug】Memory Leak cause by toVue3ComponentInstance HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from composition-api.