From e15113ecf19b870a98d5575f5154d40f76b90c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E7=A8=8B=E5=87=AF?= Date: Thu, 26 Jul 2018 18:25:56 +0800 Subject: [PATCH] refactor(*): fix type declation with this in typescript --- src/cache.ts | 4 ++-- src/debounce.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index be48e19..180e049 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -26,9 +26,9 @@ * cachedFunctionWithParam('figure', str => str.small()) * // => 'figure' */ -export default function cache (fn: (str: any) => any) { +export default function cache (fn: (str: any) => any): (str: any) => any { const cache: { [propName: string]: any } = {} - return function cachedFn () { + return function cachedFn (this: any) { const str = arguments[0] const hit = cache[str] return cache.hasOwnProperty(str) ? hit : (cache[str] = fn.apply(this, arguments)) diff --git a/src/debounce.ts b/src/debounce.ts index d2a6f5e..0fcc726 100644 --- a/src/debounce.ts +++ b/src/debounce.ts @@ -16,7 +16,7 @@ export default function debounce ( ): (...args: any[]) => void { let timer: any = null - return function (...args) { + return function (this: any, ...args) { const later = () => { timer = null func.call(this, ...args)