From: Evan You Date: Wed, 29 Jan 2025 04:02:20 +0000 (+0800) Subject: refactor: fix type errors X-Git-Tag: v3.6.0-alpha.1~16^2~134 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8008509aacee439427b5b753e2584347583f4b9a;p=thirdparty%2Fvuejs%2Fcore.git refactor: fix type errors --- diff --git a/packages/compiler-vapor/src/ir/index.ts b/packages/compiler-vapor/src/ir/index.ts index c2f5a115da..05d7b51d27 100644 --- a/packages/compiler-vapor/src/ir/index.ts +++ b/packages/compiler-vapor/src/ir/index.ts @@ -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') diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index bcc64c712f..2d1db4c0ab 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -7,8 +7,7 @@ import { } from '../directives/vShow' import { CSS_VAR_TEXT } from '../helpers/useCssVars' -type Style = StyleValue | Record -type StyleValue = string | null | undefined +type Style = string | null | undefined | Record 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( diff --git a/packages/runtime-vapor/__tests__/apiSetupContext.spec.ts b/packages/runtime-vapor/__tests__/apiSetupContext.spec.ts index 9bc5da2ea3..ea1905086a 100644 --- a/packages/runtime-vapor/__tests__/apiSetupContext.spec.ts +++ b/packages/runtime-vapor/__tests__/apiSetupContext.spec.ts @@ -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('
')() as HTMLDivElement - let prev: any - renderEffect(() => { - prev = setDynamicProps(n0, [attrs], prev, true) - }) + renderEffect(() => setDynamicProps(n0, [attrs])) return n0 }, }) diff --git a/packages/runtime-vapor/__tests__/errorHandling.spec.ts b/packages/runtime-vapor/__tests__/errorHandling.spec.ts index 2300cf9ff6..1155fe471a 100644 --- a/packages/runtime-vapor/__tests__/errorHandling.spec.ts +++ b/packages/runtime-vapor/__tests__/errorHandling.spec.ts @@ -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('
')() + const setRef = createTemplateRefSetter() setRef(el as RefEl, ref) return el }, diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 223f6f53d4..eec620480d 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -1,6 +1,6 @@ import { hyphenate, isArray, isObject, isString } from './general' -export type NormalizedStyle = Record +export type NormalizedStyle = Record export function normalizeStyle( value: unknown,