Browse Source

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

close #7955
Yuchao 2 years ago
parent
commit
17aa92b79b
2 changed files with 28 additions and 1 deletions
  1. 27 0
      packages/dts-test/tsx.test-d.tsx
  2. 1 1
      packages/runtime-dom/src/jsx.ts

+ 27 - 0
packages/dts-test/tsx.test-d.tsx

@@ -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" />
 

+ 1 - 1
packages/runtime-dom/src/jsx.ts

@@ -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