chore(types): improve of type assertion (#4141)
This commit is contained in:
parent
1e5e004d7c
commit
df0ce21836
@ -692,7 +692,7 @@ export function createCallExpression<T extends CallExpression['callee']>(
|
||||
loc,
|
||||
callee,
|
||||
arguments: args
|
||||
} as any
|
||||
} as InferCodegenNodeType<T>
|
||||
}
|
||||
|
||||
export function createFunctionExpression(
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user