]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types: improve typing (#309)
authorxiaoboost <xiaoboost@qq.com>
Wed, 16 Oct 2019 14:31:40 +0000 (22:31 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 16 Oct 2019 14:31:40 +0000 (10:31 -0400)
packages/compiler-core/__tests__/testUtils.ts
packages/runtime-dom/jsx.d.ts
packages/runtime-dom/src/modules/style.ts
packages/template-explorer/src/index.ts

index abffe1549cf0f74f82363f85c865de47dca09174..8839cd12f4255a673f2d999162b427224e301b47 100644 (file)
@@ -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<string, any>) {
   return {
     type: NodeTypes.JS_OBJECT_EXPRESSION,
     properties: Object.keys(obj).map(key => ({
index 059da503cbaee76bc1e612fdb5590f935d1aeea9..79b7a4508ef0344870120d5ada2ac605240694ce 100644 (file)
@@ -23,7 +23,7 @@
 
 interface HTMLAttributes {
   class?: any
-  style?: string | { [key: string]: string | number }
+  style?: string | Partial<CSSStyleDeclaration>
   accesskey?: string
   contenteditable?: boolean
   contextmenu?: string
index 24241c59432b861d581ae92545bcaca6812325de..5b93c2ea5b1f279506194914c34eec9984b69b07 100644 (file)
@@ -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<CSSStyleDeclaration> | 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) {
index 4fda5bf5ce2acf0be6c9559dd86e48f28fb327f7..02b4d2fe80bb040cd5729130beaf4359f6e60ebd 100644 (file)
@@ -213,12 +213,12 @@ function debounce<T extends (...args: any[]) => 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)