]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(types): improve typing (#1317)
authorAlbert Liu <814921718@qq.com>
Fri, 12 Jun 2020 14:46:44 +0000 (22:46 +0800)
committerGitHub <noreply@github.com>
Fri, 12 Jun 2020 14:46:44 +0000 (10:46 -0400)
packages/compiler-sfc/src/compileTemplate.ts
packages/runtime-core/src/components/KeepAlive.ts

index f7f858a4bd298273a665cc4d514199abb8e4e5c9..f33c86bf10fde351847c09610fdb7ea6bce36190 100644 (file)
@@ -57,20 +57,30 @@ export interface SFCTemplateCompileOptions {
    */
   transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean
 }
+  
+interface PreProcessor {
+  render(
+    source: string,
+    options: any,
+    cb: (err: Error | null, res: string) => void
+  ): void
+}
 
 function preprocess(
   { source, filename, preprocessOptions }: SFCTemplateCompileOptions,
-  preprocessor: any
+  preprocessor: PreProcessor
 ): string {
   // Consolidate exposes a callback based API, but the callback is in fact
   // called synchronously for most templating engines. In our case, we have to
   // expose a synchronous API so that it is usable in Jest transforms (which
   // have to be sync because they are applied via Node.js require hooks)
-  let res: any, err
+  let res: string = ''
+  let err: Error | null = null
+
   preprocessor.render(
     source,
     { filename, ...preprocessOptions },
-    (_err: Error | null, _res: string) => {
+    (_err, _res) => {
       if (_err) err = _err
       res = _res
     }
index 8301185ddf637aa34685197d26e3567aa0db90f7..4e18ec442b76cdf29ac97532d3e71ced081772a3 100644 (file)
@@ -252,7 +252,7 @@ function getName(comp: Component): string | void {
 
 function matches(pattern: MatchPattern, name: string): boolean {
   if (isArray(pattern)) {
-    return (pattern as any).some((p: string | RegExp) => matches(p, name))
+    return pattern.some((p: string | RegExp) => matches(p, name))
   } else if (isString(pattern)) {
     return pattern.split(',').indexOf(name) > -1
   } else if (pattern.test) {