Skip to content

Commit 7754d7e

Browse files
committed
chore: improve tests
1 parent 16352ca commit 7754d7e

File tree

2 files changed

+53
-42
lines changed

2 files changed

+53
-42
lines changed

packages/runtime-core/src/directives.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type DirectiveHook<
4040
Arg extends string = string
4141
> = (
4242
el: HostElement,
43-
binding: DirectiveBinding<Value, Arg, Modifiers>,
43+
binding: DirectiveBinding<Value, Modifiers, Arg>,
4444
vnode: VNode<any, HostElement>,
4545
prevVNode: Prev
4646
) => void
@@ -56,25 +56,25 @@ export interface ObjectDirective<
5656
Modifiers extends string = string,
5757
Arg extends string = string
5858
> {
59-
created?: DirectiveHook<HostElement, null, Value, Arg, Modifiers>
60-
beforeMount?: DirectiveHook<HostElement, null, Value, Arg, Modifiers>
61-
mounted?: DirectiveHook<HostElement, null, Value, Arg, Modifiers>
59+
created?: DirectiveHook<HostElement, null, Value, Modifiers, Arg>
60+
beforeMount?: DirectiveHook<HostElement, null, Value, Modifiers, Arg>
61+
mounted?: DirectiveHook<HostElement, null, Value, Modifiers, Arg>
6262
beforeUpdate?: DirectiveHook<
6363
HostElement,
6464
VNode<any, HostElement>,
6565
Value,
66-
Arg,
67-
Modifiers
66+
Modifiers,
67+
Arg
6868
>
6969
updated?: DirectiveHook<
7070
HostElement,
7171
VNode<any, HostElement>,
7272
Value,
73-
Arg,
74-
Modifiers
73+
Modifiers,
74+
Arg
7575
>
76-
beforeUnmount?: DirectiveHook<HostElement, null, Value, Arg, Modifiers>
77-
unmounted?: DirectiveHook<HostElement, null, Value, Arg, Modifiers>
76+
beforeUnmount?: DirectiveHook<HostElement, null, Value, Modifiers, Arg>
77+
unmounted?: DirectiveHook<HostElement, null, Value, Modifiers, Arg>
7878
getSSRProps?: SSRDirectiveHook
7979
}
8080

@@ -83,16 +83,16 @@ export type FunctionDirective<
8383
V = any,
8484
Modifiers extends string = string,
8585
Arg extends string = string
86-
> = DirectiveHook<HostElement, any, V, Arg, Modifiers>
86+
> = DirectiveHook<HostElement, any, V, Modifiers, Arg>
8787

8888
export type Directive<
8989
HostElement = any,
9090
Value = any,
9191
Modifiers extends string = string,
9292
Arg extends string = string
9393
> =
94-
| ObjectDirective<HostElement, Value, Arg, Modifiers>
95-
| FunctionDirective<HostElement, Value, Arg, Modifiers>
94+
| ObjectDirective<HostElement, Value, Modifiers, Arg>
95+
| FunctionDirective<HostElement, Value, Modifiers, Arg>
9696

9797
export type DirectiveModifiers<K extends string = string> = Record<K, boolean>
9898

test-dts/directives.test-d.ts

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Directive, expectError, expectType } from './index'
1+
import { ObjectDirective } from '@vue/runtime-core'
2+
import { Directive, expectError, expectType, vModelText } from './index'
23

34
type ExtractBinding<T> = T extends (
45
el: any,
@@ -13,35 +14,45 @@ declare function testDirective<
1314
Value,
1415
Modifiers extends string = string,
1516
Arg extends string = string
16-
>(): ExtractBinding<Directive<any, Value, Arg, Modifiers>>
17+
>(): ExtractBinding<Directive<any, Value, Modifiers, Arg>>
1718

18-
expectType<{
19-
value: number
20-
oldValue: number | null
21-
arg?: 'Arg'
22-
modifiers: Record<'a' | 'b', boolean>
23-
}>(testDirective<number, 'a' | 'b', 'Arg'>())
24-
25-
expectError<{
26-
value: number
27-
oldValue: number | null
28-
arg?: 'Arg'
29-
modifiers: Record<'a' | 'b', boolean>
19+
describe('vmodel', () => {
20+
expectType<ObjectDirective<any, any, 'trim' | 'number' | 'lazy', string>>(
21+
vModelText
22+
)
3023
// @ts-expect-error
31-
}>(testDirective<number, 'a', 'Arg'>())
24+
expectType<ObjectDirective<any, any, 'trim' | 'number', string>>(vModelText)
25+
})
3226

33-
expectType<{
34-
value: number
35-
oldValue: number | null
36-
arg?: 'Arg'
37-
modifiers: Record<'a' | 'b', boolean>
38-
// @ts-expect-error
39-
}>(testDirective<number, 'a' | 'b', 'Argx'>())
27+
describe('custom', () => {
28+
expectType<{
29+
value: number
30+
oldValue: number | null
31+
arg?: 'Arg'
32+
modifiers: Record<'a' | 'b', boolean>
33+
}>(testDirective<number, 'a' | 'b', 'Arg'>())
4034

41-
expectType<{
42-
value: number
43-
oldValue: number | null
44-
arg?: 'Arg'
45-
modifiers: Record<'a' | 'b', boolean>
46-
// @ts-expect-error
47-
}>(testDirective<string, 'a' | 'b', 'Arg'>())
35+
expectError<{
36+
value: number
37+
oldValue: number | null
38+
arg?: 'Arg'
39+
modifiers: Record<'a' | 'b', boolean>
40+
// @ts-expect-error
41+
}>(testDirective<number, 'a', 'Arg'>())
42+
43+
expectType<{
44+
value: number
45+
oldValue: number | null
46+
arg?: 'Arg'
47+
modifiers: Record<'a' | 'b', boolean>
48+
// @ts-expect-error
49+
}>(testDirective<number, 'a' | 'b', 'Argx'>())
50+
51+
expectType<{
52+
value: number
53+
oldValue: number | null
54+
arg?: 'Arg'
55+
modifiers: Record<'a' | 'b', boolean>
56+
// @ts-expect-error
57+
}>(testDirective<string, 'a' | 'b', 'Arg'>())
58+
})

0 commit comments

Comments
 (0)