]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: fix type errors
authorEvan You <evan@vuejs.org>
Wed, 29 Jan 2025 04:02:20 +0000 (12:02 +0800)
committerEvan You <evan@vuejs.org>
Wed, 29 Jan 2025 04:08:32 +0000 (12:08 +0800)
packages/compiler-vapor/src/ir/index.ts
packages/runtime-dom/src/modules/style.ts
packages/runtime-vapor/__tests__/apiSetupContext.spec.ts
packages/runtime-vapor/__tests__/errorHandling.spec.ts
packages/shared/src/normalizeProp.ts

index c2f5a115da31642ffe25b98fc46e07c31eab973b..05d7b51d278d433418aba74a5764b92e4caa3992 100644 (file)
@@ -42,7 +42,7 @@ export interface BaseIRNode {
   type: IRNodeTypes
 }
 
-export type CoreHelper = keyof typeof import('packages/runtime-core/src')
+export type CoreHelper = keyof typeof import('packages/runtime-dom/src')
 
 export type VaporHelper = keyof typeof import('packages/runtime-vapor/src')
 
index bcc64c712f0aca0654b6b00b06a733a85953ae2a..2d1db4c0abdb6af07b149c196c7c31ba424b61d5 100644 (file)
@@ -7,8 +7,7 @@ import {
 } from '../directives/vShow'
 import { CSS_VAR_TEXT } from '../helpers/useCssVars'
 
-type Style = StyleValue | Record<string, StyleValue | StyleValue[]>
-type StyleValue = string | null | undefined
+type Style = string | null | undefined | Record<string, unknown>
 
 const displayRE = /(^|;)\s*display\s*:/
 
@@ -68,15 +67,11 @@ export function patchStyle(el: Element, prev: Style, next: Style): void {
 const semicolonRE = /[^\\];\s*$/
 const importantRE = /\s*!important$/
 
-function setStyle(
-  style: CSSStyleDeclaration,
-  name: string,
-  val: StyleValue | StyleValue[],
-) {
-  if (isArray(val)) {
-    val.forEach(v => setStyle(style, name, v))
+function setStyle(style: CSSStyleDeclaration, name: string, rawVal: unknown) {
+  if (isArray(rawVal)) {
+    rawVal.forEach(v => setStyle(style, name, v))
   } else {
-    if (val == null) val = ''
+    const val = rawVal == null ? '' : String(rawVal)
     if (__DEV__) {
       if (semicolonRE.test(val)) {
         warn(
index 9bc5da2ea3cb99baad52e12845d45c9add755472..ea1905086aca6c0034b109aaf44b4a174a56f44b 100644 (file)
@@ -74,10 +74,7 @@ describe('api: setup context', () => {
       inheritAttrs: false,
       setup(_props, { attrs }) {
         const el = document.createElement('div')
-        let prev: any
-        renderEffect(() => {
-          prev = setDynamicProps(el, [attrs], prev, true)
-        })
+        renderEffect(() => setDynamicProps(el, [attrs]))
         return el
       },
     })
@@ -113,10 +110,7 @@ describe('api: setup context', () => {
         const n0 = createComponent(Wrapper, null, {
           default: () => {
             const n0 = template('<div>')() as HTMLDivElement
-            let prev: any
-            renderEffect(() => {
-              prev = setDynamicProps(n0, [attrs], prev, true)
-            })
+            renderEffect(() => setDynamicProps(n0, [attrs]))
             return n0
           },
         })
index 2300cf9ff6e4ed7f5b0413e7b65ab53644b89410..1155fe471a6d7bc43ef120a96cb1cce75b2769d4 100644 (file)
@@ -6,7 +6,7 @@ import {
   watch,
   watchEffect,
 } from '@vue/runtime-dom'
-import { createComponent, setRef, template } from '../src'
+import { createComponent, createTemplateRefSetter, template } from '../src'
 import { makeRender } from './_utils'
 import type { VaporComponent } from '../src/component'
 import type { RefEl } from '../src/apiTemplateRef'
@@ -229,6 +229,7 @@ describe('error handling', () => {
     const Child = {
       render() {
         const el = template('<div>')()
+        const setRef = createTemplateRefSetter()
         setRef(el as RefEl, ref)
         return el
       },
index 223f6f53d4b1f70810cbba0798418c656a655a88..eec620480de0bd47f0d1df66c4165a162b685a21 100644 (file)
@@ -1,6 +1,6 @@
 import { hyphenate, isArray, isObject, isString } from './general'
 
-export type NormalizedStyle = Record<string, string>
+export type NormalizedStyle = Record<string, unknown>
 
 export function normalizeStyle(
   value: unknown,