fix(types): the directive's modifiers should be optional (#12605)

* fix(types): the directive's modifiers should be optional

* fix: test

---------

Co-authored-by: edison <daiwei521@126.com>
This commit is contained in:
Buer Yang 2025-03-19 11:38:59 +08:00 committed by GitHub
parent 4fea167b57
commit 10e54dcc86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View File

@ -9,7 +9,7 @@ app.directive<HTMLElement, string, 'prevent' | 'stop', 'arg1' | 'arg2'>(
mounted(el, binding) {
expectType<HTMLElement>(el)
expectType<string>(binding.value)
expectType<{ prevent: boolean; stop: boolean }>(binding.modifiers)
expectType<{ prevent?: boolean; stop?: boolean }>(binding.modifiers)
expectType<'arg1' | 'arg2'>(binding.arg!)
// @ts-expect-error not any

View File

@ -29,7 +29,7 @@ describe('custom', () => {
value: number
oldValue: number | null
arg?: 'Arg'
modifiers: Record<'a' | 'b', boolean>
modifiers: Partial<Record<'a' | 'b', boolean>>
}>(testDirective<number, 'a' | 'b', 'Arg'>())
expectType<{

View File

@ -111,7 +111,9 @@ export type Directive<
| ObjectDirective<HostElement, Value, Modifiers, Arg>
| FunctionDirective<HostElement, Value, Modifiers, Arg>
export type DirectiveModifiers<K extends string = string> = Record<K, boolean>
export type DirectiveModifiers<K extends string = string> = Partial<
Record<K, boolean>
>
export function validateDirectiveName(name: string): void {
if (isBuiltInDirective(name)) {