Comments (14)
- If you don't need typescript types
export default createComponent({
setup(props) {
return {}
},
props: {
simple: {
type: String,
required: true
},
} as const
})
interface Props {
simple: string
}
- If you need typescript types
export default createComponent({
setup(props) {
return {}
},
props: ({
advanced: {
required: true
},
} as unknown) as Props
})
interface Props {
advanced: {
a: string
b: number
}
}
from composition-api.
THX very much
from composition-api.
I still got error:
Conversion of type '{ readonly list: ArrayConstructor; }' to type 'Props' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Types of property 'list' are incompatible.
Type 'ArrayConstructor' is missing the following properties from type 'GridMenuList[]': pop, push, concat, join, and 27 more.Vetur(2352)
Conversion of type '{ readonly list: ArrayConstructor; }' to type 'Props' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Types of property 'list' are incompatible.
Type 'ArrayConstructor' is not comparable to type 'GridMenuList[]'.
when
interface Props {
list: GridMenuList[]
}
const DropdownGrid = createComponent({
props: ({
list: Array
} as const) as Props,
setup(props) {
...
So maybe I still need to convert to unknown first?
from composition-api.
There was an error in my example, I've fixed it.
from composition-api.
I got error when
as unknown as Props as const
as unknown as const as Props
and no const effect when as const as unknown as Props
So how should I do?
from composition-api.
Oh thx, so when I want types I can not convert to const, is that right?
from composition-api.
By the way, I don't think we need that parentheses(I am not sure whether I spell right). It seems ok when I remove it.
from composition-api.
I don't use as const
with interface Props
If you want to be sure to not assign to props I think you can do as unknown as Readonly<Props>
from composition-api.
My linter adds parenthesis but It's not required
from composition-api.
@GODOFHOPE Try v2.2.0.
from composition-api.
🆗,I'll try ^-^
from composition-api.
Excuse me ,waht's impoving? I cannot feel any enhancement. Could you tell me more specificitly?
I stitll catch error whtn writing originally, yet I still needs to convert to unknown.
from composition-api.
I noticed the provide/inject types improve, by checking your commits and I alse noticed an enhancement with states, but none about props.
from composition-api.
@GODOFHOPE Can you show me your codes? An online example would be great.
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.