Skip to content

Commit df0ce21

Browse files
authored
chore(types): improve of type assertion (vuejs#4141)
1 parent 1e5e004 commit df0ce21

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/compiler-core/src/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ export function createCallExpression<T extends CallExpression['callee']>(
692692
loc,
693693
callee,
694694
arguments: args
695-
} as any
695+
} as InferCodegenNodeType<T>
696696
}
697697

698698
export function createFunctionExpression(

packages/compiler-core/src/errors.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@ export function defaultOnWarn(msg: CompilerError) {
1717
__DEV__ && console.warn(`[Vue warn] ${msg.message}`)
1818
}
1919

20+
type InferCompilerError<T> = T extends ErrorCodes
21+
? CoreCompilerError
22+
: CompilerError
23+
2024
export function createCompilerError<T extends number>(
2125
code: T,
2226
loc?: SourceLocation,
2327
messages?: { [code: number]: string },
2428
additionalMessage?: string
25-
): T extends ErrorCodes ? CoreCompilerError : CompilerError {
29+
): InferCompilerError<T> {
2630
const msg =
2731
__DEV__ || !__BROWSER__
2832
? (messages || errorMessages)[code] + (additionalMessage || ``)
2933
: code
30-
const error = new SyntaxError(String(msg)) as CompilerError
34+
const error = new SyntaxError(String(msg)) as InferCompilerError<T>
3135
error.code = code
3236
error.loc = loc
33-
return error as any
37+
return error
3438
}
3539

3640
export const enum ErrorCodes {

0 commit comments

Comments
 (0)