]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): allow falsy value types in `StyleValue` (#7954)
authorYuchao <yuchao.sydneyuni@gmail.com>
Fri, 10 Nov 2023 06:23:54 +0000 (17:23 +1100)
committerGitHub <noreply@github.com>
Fri, 10 Nov 2023 06:23:54 +0000 (14:23 +0800)
close #7955

packages/dts-test/tsx.test-d.tsx
packages/runtime-dom/src/jsx.ts

index 04915a9673f4f95477171831b9cd2a41f76b9ca8..47555a03c0bb19b45ae11bf6bd316b10a8e3bd5b 100644 (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" />
 
index 7769418653edd731ded61d972495abfba6892250..3ab2de8b7723ca712c97fa457717d29ed147ca37 100644 (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