]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(types): improve of type assertion (#4141)
authorwebfansplz <308241863@qq.com>
Mon, 19 Jul 2021 14:32:07 +0000 (22:32 +0800)
committerGitHub <noreply@github.com>
Mon, 19 Jul 2021 14:32:07 +0000 (10:32 -0400)
packages/compiler-core/src/ast.ts
packages/compiler-core/src/errors.ts

index 7bd714694d8a673f97dc3222d1e19e21b893338a..0694b4220d144c7c59f8ac6829b042f8228f7ef5 100644 (file)
@@ -692,7 +692,7 @@ export function createCallExpression<T extends CallExpression['callee']>(
     loc,
     callee,
     arguments: args
-  } as any
+  } as InferCodegenNodeType<T>
 }
 
 export function createFunctionExpression(
index 3cae36da6c14535a8b12c6fe039186ea0d410016..09ec72901356c8cb0275074a4828778acacee0f6 100644 (file)
@@ -17,20 +17,24 @@ export function defaultOnWarn(msg: CompilerError) {
   __DEV__ && console.warn(`[Vue warn] ${msg.message}`)
 }
 
+type InferCompilerError<T> = T extends ErrorCodes
+  ? CoreCompilerError
+  : CompilerError
+
 export function createCompilerError<T extends number>(
   code: T,
   loc?: SourceLocation,
   messages?: { [code: number]: string },
   additionalMessage?: string
-): T extends ErrorCodes ? CoreCompilerError : CompilerError {
+): InferCompilerError<T> {
   const msg =
     __DEV__ || !__BROWSER__
       ? (messages || errorMessages)[code] + (additionalMessage || ``)
       : code
-  const error = new SyntaxError(String(msg)) as CompilerError
+  const error = new SyntaxError(String(msg)) as InferCompilerError<T>
   error.code = code
   error.loc = loc
-  return error as any
+  return error
 }
 
 export const enum ErrorCodes {