Skip to content

Commit fba78d4

Browse files
ktsnyyx990803
authored andcommitted
Update types for new features of v2.1 (vuejs#4305)
* add types for scoped slots * update nextTick types for returning promise * improve scoped slot type
1 parent db3e1c7 commit fba78d4

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

types/test/options-test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,37 @@ Vue.component('component', {
162162
delimiters: ["${", "}"]
163163
} as ComponentOptions<Component>);
164164

165+
Vue.component('component-with-scoped-slot', {
166+
render (h) {
167+
interface ScopedSlotProps {
168+
msg: string
169+
}
170+
171+
return h('div', [
172+
h('child', [
173+
// default scoped slot as children
174+
(props: ScopedSlotProps) => [h('span', [props.msg])]
175+
]),
176+
h('child', {
177+
scopedSlots: {
178+
// named scoped slot as vnode data
179+
item: (props: ScopedSlotProps) => [h('span', [props.msg])]
180+
}
181+
})
182+
])
183+
},
184+
components: {
185+
child: {
186+
render (h) {
187+
return h('div', [
188+
this.$scopedSlots['default']({ msg: 'hi' }),
189+
this.$scopedSlots['item']({ msg: 'hello' })
190+
])
191+
}
192+
} as ComponentOptions<Vue>
193+
}
194+
} as ComponentOptions<Vue>)
195+
165196
Vue.component('functional-component', {
166197
props: ['prop'],
167198
functional: true,

types/test/vue-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Test extends Vue {
4545
this.$nextTick(function() {
4646
this.$nextTick;
4747
});
48+
this.$nextTick().then(() => {});
4849
this.$createElement("div", {}, "message");
4950
}
5051

@@ -71,6 +72,7 @@ class Test extends Vue {
7172
}
7273
});
7374
this.nextTick(() => {});
75+
this.nextTick().then(() => {});
7476
this.set({}, "", "");
7577
this.set([true, false, true], 1, true);
7678
this.delete({}, "");

types/vnode.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Vue } from "./vue";
22

3-
export type VNodeChildren = VNodeChildrenArrayContents | string;
3+
export type ScopedSlot = (props: any) => VNodeChildrenArrayContents | string;
4+
5+
export type VNodeChildren = VNodeChildrenArrayContents | [ScopedSlot] | string;
46
export interface VNodeChildrenArrayContents {
57
[x: number]: VNode | string | VNodeChildren;
68
}
@@ -34,6 +36,7 @@ export interface VNodeComponentOptions {
3436
export interface VNodeData {
3537
key?: string | number;
3638
slot?: string;
39+
scopedSlots?: { [key: string]: ScopedSlot };
3740
ref?: string;
3841
tag?: string;
3942
staticClass?: string;

types/vue.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
DirectiveOptions,
99
DirectiveFunction
1010
} from "./options";
11-
import { VNode, VNodeData, VNodeChildren } from "./vnode";
11+
import { VNode, VNodeData, VNodeChildren, ScopedSlot } from "./vnode";
1212
import { PluginFunction, PluginObject } from "./plugin";
1313

1414
export type CreateElement = {
@@ -40,6 +40,7 @@ export declare class Vue {
4040
readonly $children: Vue[];
4141
readonly $refs: { [key: string]: Vue | Element | Vue[] | Element[]};
4242
readonly $slots: { [key: string]: VNode[] };
43+
readonly $scopedSlots: { [key: string]: ScopedSlot };
4344
readonly $isServer: boolean;
4445

4546
$mount(elementOrSelector?: Element | String, hydrating?: boolean): this;
@@ -56,7 +57,8 @@ export declare class Vue {
5657
$once(event: string, callback: Function): this;
5758
$off(event?: string, callback?: Function): this;
5859
$emit(event: string, ...args: any[]): this;
59-
$nextTick(callback?: (this: this) => void): void;
60+
$nextTick(callback: (this: this) => void): void;
61+
$nextTick(): Promise<void>;
6062
$createElement: CreateElement;
6163

6264
static config: {
@@ -69,6 +71,7 @@ export declare class Vue {
6971

7072
static extend(options: ComponentOptions<Vue> | FunctionalComponentOptions): typeof Vue;
7173
static nextTick(callback: () => void, context?: any[]): void;
74+
static nextTick(): Promise<void>
7275
static set<T>(object: Object, key: string, value: T): T;
7376
static set<T>(array: T[], key: number, value: T): T;
7477
static delete(object: Object, key: string): void;

0 commit comments

Comments
 (0)