how to use props to define ts class type #10422
Replies: 6 comments
-
https://vuejs.org/guide/typescript/composition-api#typing-component-props |
Beta Was this translation helpful? Give feedback.
-
并没用,示例里是个interface, 而我这里是个class, 就是识别不出来 |
Beta Was this translation helpful? Give feedback.
-
我好像没复现3.2、3.4都试过了,也有可能是IDE的问题 |
Beta Was this translation helpful? Give feedback.
-
官方是这么说的 语法限制 |
Beta Was this translation helpful? Give feedback.
-
你是通过use函数导出的class对象吗 |
Beta Was this translation helpful? Give feedback.
-
啥意思 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Vue version
2.7 3.2
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-zjhkvo?file=src%2FApp.vue
Steps to reproduce
const props = withDefaults(
defineProps<{
crud: BaseListCrud
layout?: string
pageSizes?: number[]
tableAttrs?: {
[key: string]: any
}
tableTitle?: string
}>(),
{
pageSizes: () => [10, 20, 30, 40, 50],
// tableAttrs: () => {},
layout: 'total, sizes, prev, pager, next, jumper',
tableTitle: '数据列表'
}
)
What is expected?
Vue: Type
{ search: { url: string; method: string; pageData: { currentPage: number; pageSize: number; sortName?: string | undefined; sortOrder?: '' | 'desc' | 'asc' | undefined; } | null; callback?: ((result: ListResult) => ListResult) | undefined; }; ... 35 more ...; getRouterParams: () => Promise<...>; }
is not assignable to type BaseListCrud
What is actually happening?
crud is a ts class instance, but when it used by use Function, father component can not assign type
i try crud: BaseListCrud or crud; PropType it is not correctly
System Info
No response
Any additional comments?
No response
Beta Was this translation helpful? Give feedback.
All reactions