fix(types): allow falsy value types in `StyleValue` (#7954)

close #7955
This commit is contained in:
Yuchao 2023-11-10 17:23:54 +11:00 committed by GitHub
parent d5fd343555
commit 17aa92b79b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -17,6 +17,33 @@ expectType<JSX.Element>(
<div style={[{ color: 'red' }, [{ fontSize: '1em' }]]} />
)
// #7955
expectType<JSX.Element>(
<div style={[undefined, '', null, false]} />
)
expectType<JSX.Element>(
<div style={undefined} />
)
expectType<JSX.Element>(
<div style={null} />
)
expectType<JSX.Element>(
<div style={''} />
)
expectType<JSX.Element>(
<div style={false} />
)
// @ts-expect-error
;<div style={[0]} />
// @ts-expect-error
;<div style={0} />
// @ts-expect-error unknown prop
;<div foo="bar" />

View File

@ -244,7 +244,7 @@ interface AriaAttributes {
}
// Vue's style normalization supports nested arrays
export type StyleValue = string | CSSProperties | Array<StyleValue>
export type StyleValue = false | null | undefined | string | CSSProperties | Array<StyleValue>
export interface HTMLAttributes extends AriaAttributes, EventHandlers<Events> {
innerHTML?: string