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,
|
loc,
|
||||||
callee,
|
callee,
|
||||||
arguments: args
|
arguments: args
|
||||||
} as any
|
} as InferCodegenNodeType<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFunctionExpression(
|
export function createFunctionExpression(
|
||||||
|
@ -17,20 +17,24 @@ export function defaultOnWarn(msg: CompilerError) {
|
|||||||
__DEV__ && console.warn(`[Vue warn] ${msg.message}`)
|
__DEV__ && console.warn(`[Vue warn] ${msg.message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InferCompilerError<T> = T extends ErrorCodes
|
||||||
|
? CoreCompilerError
|
||||||
|
: CompilerError
|
||||||
|
|
||||||
export function createCompilerError<T extends number>(
|
export function createCompilerError<T extends number>(
|
||||||
code: T,
|
code: T,
|
||||||
loc?: SourceLocation,
|
loc?: SourceLocation,
|
||||||
messages?: { [code: number]: string },
|
messages?: { [code: number]: string },
|
||||||
additionalMessage?: string
|
additionalMessage?: string
|
||||||
): T extends ErrorCodes ? CoreCompilerError : CompilerError {
|
): InferCompilerError<T> {
|
||||||
const msg =
|
const msg =
|
||||||
__DEV__ || !__BROWSER__
|
__DEV__ || !__BROWSER__
|
||||||
? (messages || errorMessages)[code] + (additionalMessage || ``)
|
? (messages || errorMessages)[code] + (additionalMessage || ``)
|
||||||
: code
|
: code
|
||||||
const error = new SyntaxError(String(msg)) as CompilerError
|
const error = new SyntaxError(String(msg)) as InferCompilerError<T>
|
||||||
error.code = code
|
error.code = code
|
||||||
error.loc = loc
|
error.loc = loc
|
||||||
return error as any
|
return error
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum ErrorCodes {
|
export const enum ErrorCodes {
|
||||||
|
Loading…
Reference in New Issue
Block a user