Skip to content

Commit 4b71706

Browse files
authored
fix(types): widen directive arg type from string to any (#13758)
closes #13757
1 parent 9c27951 commit 4b71706

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

packages-private/dts-test/directives.test-d.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ExtractBinding<T> = T extends (
1313
declare function testDirective<
1414
Value,
1515
Modifiers extends string = string,
16-
Arg extends string = string,
16+
Arg = any,
1717
>(): ExtractBinding<Directive<any, Value, Modifiers, Arg>>
1818

1919
describe('vmodel', () => {
@@ -44,15 +44,37 @@ describe('custom', () => {
4444
value: number
4545
oldValue: number | null
4646
arg?: 'Arg'
47-
modifiers: Record<'a' | 'b', boolean>
47+
modifiers: Partial<Record<'a' | 'b', boolean>>
4848
// @ts-expect-error
4949
}>(testDirective<number, 'a' | 'b', 'Argx'>())
5050

5151
expectType<{
5252
value: number
5353
oldValue: number | null
5454
arg?: 'Arg'
55-
modifiers: Record<'a' | 'b', boolean>
55+
modifiers: Partial<Record<'a' | 'b', boolean>>
5656
// @ts-expect-error
5757
}>(testDirective<string, 'a' | 'b', 'Arg'>())
58+
59+
expectType<{
60+
value: number
61+
oldValue: number | null
62+
arg?: HTMLElement
63+
modifiers: Partial<Record<'a' | 'b', boolean>>
64+
}>(testDirective<number, 'a' | 'b', HTMLElement>())
65+
66+
expectType<{
67+
value: number
68+
oldValue: number | null
69+
arg?: HTMLElement
70+
modifiers: Partial<Record<'a' | 'b', boolean>>
71+
// @ts-expect-error
72+
}>(testDirective<number, 'a' | 'b', string>())
73+
74+
expectType<{
75+
value: number
76+
oldValue: number | null
77+
arg?: HTMLElement
78+
modifiers: Partial<Record<'a' | 'b', boolean>>
79+
}>(testDirective<number, 'a' | 'b'>())
5880
})

packages/runtime-core/src/apiCreateApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export interface App<HostElement = any> {
5050
HostElement = any,
5151
Value = any,
5252
Modifiers extends string = string,
53-
Arg extends string = string,
53+
Arg = any,
5454
>(
5555
name: string,
5656
): Directive<HostElement, Value, Modifiers, Arg> | undefined
5757
directive<
5858
HostElement = any,
5959
Value = any,
6060
Modifiers extends string = string,
61-
Arg extends string = string,
61+
Arg = any,
6262
>(
6363
name: string,
6464
directive: Directive<HostElement, Value, Modifiers, Arg>,

packages/runtime-core/src/directives.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@ import { pauseTracking, resetTracking, traverse } from '@vue/reactivity'
2828
export interface DirectiveBinding<
2929
Value = any,
3030
Modifiers extends string = string,
31-
Arg extends string = string,
31+
Arg = any,
3232
> {
3333
instance: ComponentPublicInstance | Record<string, any> | null
3434
value: Value
3535
oldValue: Value | null
3636
arg?: Arg
3737
modifiers: DirectiveModifiers<Modifiers>
38-
dir: ObjectDirective<any, Value>
38+
dir: ObjectDirective<any, Value, Modifiers, Arg>
3939
}
4040

4141
export type DirectiveHook<
4242
HostElement = any,
4343
Prev = VNode<any, HostElement> | null,
4444
Value = any,
4545
Modifiers extends string = string,
46-
Arg extends string = string,
46+
Arg = any,
4747
> = (
4848
el: HostElement,
4949
binding: DirectiveBinding<Value, Modifiers, Arg>,
@@ -54,7 +54,7 @@ export type DirectiveHook<
5454
export type SSRDirectiveHook<
5555
Value = any,
5656
Modifiers extends string = string,
57-
Arg extends string = string,
57+
Arg = any,
5858
> = (
5959
binding: DirectiveBinding<Value, Modifiers, Arg>,
6060
vnode: VNode,
@@ -64,7 +64,7 @@ export interface ObjectDirective<
6464
HostElement = any,
6565
Value = any,
6666
Modifiers extends string = string,
67-
Arg extends string = string,
67+
Arg = any,
6868
> {
6969
/**
7070
* @internal without this, ts-expect-error in directives.test-d.ts somehow
@@ -99,14 +99,14 @@ export type FunctionDirective<
9999
HostElement = any,
100100
V = any,
101101
Modifiers extends string = string,
102-
Arg extends string = string,
102+
Arg = any,
103103
> = DirectiveHook<HostElement, any, V, Modifiers, Arg>
104104

105105
export type Directive<
106106
HostElement = any,
107107
Value = any,
108108
Modifiers extends string = string,
109-
Arg extends string = string,
109+
Arg = any,
110110
> =
111111
| ObjectDirective<HostElement, Value, Modifiers, Arg>
112112
| FunctionDirective<HostElement, Value, Modifiers, Arg>
@@ -125,8 +125,8 @@ export function validateDirectiveName(name: string): void {
125125
export type DirectiveArguments = Array<
126126
| [Directive | undefined]
127127
| [Directive | undefined, any]
128-
| [Directive | undefined, any, string]
129-
| [Directive | undefined, any, string | undefined, DirectiveModifiers]
128+
| [Directive | undefined, any, any]
129+
| [Directive | undefined, any, any, DirectiveModifiers]
130130
>
131131

132132
/**

0 commit comments

Comments
 (0)