src/messages.ts
Properties |
| code |
code:
|
Type : string
|
| message |
message:
|
Type : string
|
| type |
type:
|
Type : WarningTypes
|
| warned |
warned:
|
Type : boolean
|
| Optional |
export enum WarningTypes {
WARNING = 'Warning',
DEPRECATION = 'DeprecationWarning',
}
export function warn(warning: Warning) {
// Only show a given warning once
if (warning.warned) {
return;
}
warning.warned = true;
if (typeof process !== 'undefined' && process.emitWarning) {
// @types/node doesn't recognize the emitWarning syntax which
// accepts a config object, so `as any` it is
// https://nodejs.org/docs/latest-v8.x/api/process.html#process_process_emitwarning_warning_options
// eslint-disable-next-line @typescript-eslint/no-explicit-any
process.emitWarning(warning.message, warning as any);
} else {
console.warn(warning.message);
}
}
export interface Warning {
code: string;
type: WarningTypes;
message: string;
warned?: boolean;
}