From: xiaoboost Date: Wed, 16 Oct 2019 14:31:40 +0000 (+0800) Subject: types: improve typing (#309) X-Git-Tag: v3.0.0-alpha.0~403 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=32499b16e7d88b0c6f53c6a0e0998e4a40d1c1f3;p=thirdparty%2Fvuejs%2Fcore.git types: improve typing (#309) --- diff --git a/packages/compiler-core/__tests__/testUtils.ts b/packages/compiler-core/__tests__/testUtils.ts index abffe1549c..8839cd12f4 100644 --- a/packages/compiler-core/__tests__/testUtils.ts +++ b/packages/compiler-core/__tests__/testUtils.ts @@ -17,7 +17,7 @@ const bracketsRE = /^\[|\]$/g // e.g. // - createObjectMatcher({ 'foo': '[bar]' }) matches { foo: bar } // - createObjectMatcher({ '[foo]': 'bar' }) matches { [foo]: "bar" } -export function createObjectMatcher(obj: any) { +export function createObjectMatcher(obj: Record) { return { type: NodeTypes.JS_OBJECT_EXPRESSION, properties: Object.keys(obj).map(key => ({ diff --git a/packages/runtime-dom/jsx.d.ts b/packages/runtime-dom/jsx.d.ts index 059da503cb..79b7a4508e 100644 --- a/packages/runtime-dom/jsx.d.ts +++ b/packages/runtime-dom/jsx.d.ts @@ -23,7 +23,7 @@ interface HTMLAttributes { class?: any - style?: string | { [key: string]: string | number } + style?: string | Partial accesskey?: string contenteditable?: boolean contextmenu?: string diff --git a/packages/runtime-dom/src/modules/style.ts b/packages/runtime-dom/src/modules/style.ts index 24241c5943..5b93c2ea5b 100644 --- a/packages/runtime-dom/src/modules/style.ts +++ b/packages/runtime-dom/src/modules/style.ts @@ -1,14 +1,16 @@ import { isString } from '@vue/shared' -export function patchStyle(el: any, prev: any, next: any) { - const { style } = el +type Style = string | Partial | null + +export function patchStyle(el: Element, prev: Style, next: Style) { + const style = (el as HTMLElement).style if (!next) { el.removeAttribute('style') } else if (isString(next)) { style.cssText = next } else { for (const key in next) { - style[key] = next[key] + style[key] = next[key] as string } if (prev && !isString(prev)) { for (const key in prev) { diff --git a/packages/template-explorer/src/index.ts b/packages/template-explorer/src/index.ts index 4fda5bf5ce..02b4d2fe80 100644 --- a/packages/template-explorer/src/index.ts +++ b/packages/template-explorer/src/index.ts @@ -213,12 +213,12 @@ function debounce any>( fn: T, delay: number = 300 ): T { - let prevTimer: NodeJS.Timeout | null = null + let prevTimer: number | null = null return ((...args: any[]) => { if (prevTimer) { clearTimeout(prevTimer) } - prevTimer = setTimeout(() => { + prevTimer = window.setTimeout(() => { fn(...args) prevTimer = null }, delay)