-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Improve Vue type declarations for more canonical usage #5887
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
Changes from 1 commit
5b5a88f
385a744
8cd5b9c
540a38f
f34f4f6
b1f40ce
355ff75
bc54007
e7ea5bb
ebde0b1
d78d14b
fc83771
a50c838
3c86b10
33a106c
0f586db
1092efe
ebd8c0b
c628103
e4a8545
f7ebfa3
bb0ff30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,18 +32,18 @@ export type CreateElement = { | |
(tag: AsyncComponent<any, any, any, any>, data?: VNodeData, children?: VNodeChildren): VNode; | ||
} | ||
|
||
export interface Vue<Data = object, Methods = object, Computed = object, Props = object> { | ||
$data: Data; | ||
export interface Vue { | ||
readonly $el: HTMLElement; | ||
readonly $options: ComponentOptions<Data, Methods, Computed, Props>; | ||
readonly $options: ComponentOptions<any, any, any, any>; | ||
readonly $parent: Vue; | ||
readonly $root: Vue; | ||
readonly $children: Vue[]; | ||
readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[] }; | ||
readonly $slots: { [key: string]: VNode[] }; | ||
readonly $scopedSlots: { [key: string]: ScopedSlot }; | ||
readonly $isServer: boolean; | ||
readonly $props: Props; | ||
readonly $data: Record<string, any>; | ||
readonly $props: Record<string, any>; | ||
readonly $ssrContext: any; | ||
|
||
$mount(elementOrSelector?: Element | String, hydrating?: boolean): this; | ||
|
@@ -70,7 +70,7 @@ export interface Vue<Data = object, Methods = object, Computed = object, Props = | |
$createElement: CreateElement; | ||
} | ||
|
||
export type CombinedVueInstance<Data, Methods, Computed, Props> = Data & Methods & Computed & Props & Vue<Data, Methods, Computed, Props> | ||
export type CombinedVueInstance<Data, Methods, Computed, Props> = Data & Methods & Computed & Props & Vue; | ||
export type ExtendedVue<Constructor extends VueConstructor, Data, Methods, Computed, Props> = | ||
(new (...args: any[]) => CombinedVueInstance<Data, Methods, Computed, Props>) & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As new (options: any) => CombinedVueInstance<Data, Methods, Computed, Props> Not sure whether we could annotate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@ktsn ExtendedVue creates an intersection with the mixin constructor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I didn't understand about the mixin constructor correctly. Thank you for the explanation. |
||
Constructor; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also make Vue generic so
$data
and$props
can be typed. But I wonder if it is an overkill.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally made it generic but ran into problems.
Namely,
VueConstructor
has two construct signatures. Each of those signatures has two different sets of type parameters. They each constructed, at least in part, a Vue<Data, Methods, Computed, Props>`, but each gave different type arguments.When extending a
Vue<Data, Methods, Computed, Props>, TypeScript tries to find the right construct signature, but it can't because it's not really possible to make a meaningful set of type arguments for
Vue` that would create the same output type for both signatures.What it comes down to is that TypeScript has always had an assumption that the type parameters of a construct signature have had a direct correlation with the type parameters of the constructed type - but that's not entirely the case here. At least, that's my understanding of the problem.
So I could try to address this, but maybe down the line. Plus, does anyone need to access
$data
and$props
outside of debugging?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation!
Indeed,
$data
and$props
are mainly for advanced usage like delegate / wrapper component (example). We would like to check template code in future. So a$props
or$data
might be helpful.For ordinary users,
Record
should be enough.