Skip to content

Commit

Permalink
fix(types): allow falsy value types in StyleValue (#7954)
Browse files Browse the repository at this point in the history
close #7955
  • Loading branch information
yuwu9145 authored Nov 10, 2023
1 parent d5fd343 commit 17aa92b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/dts-test/tsx.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17aa92b

Please sign in to comment.