warning.d.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. export type preMessageFn = (message: string, type: 'warning' | 'note') => string | null | undefined | number;
  2. /**
  3. * Pre warning enable you to parse content before console.error.
  4. * Modify to null will prevent warning.
  5. */
  6. export declare const preMessage: (fn: preMessageFn) => void;
  7. /**
  8. * Warning if condition not match.
  9. * @param valid Condition
  10. * @param message Warning message
  11. * @example
  12. * ```js
  13. * warning(false, 'some error'); // print some error
  14. * warning(true, 'some error'); // print nothing
  15. * warning(1 === 2, 'some error'); // print some error
  16. * ```
  17. */
  18. export declare function warning(valid: boolean, message: string): void;
  19. /** @see Similar to {@link warning} */
  20. export declare function note(valid: boolean, message: string): void;
  21. export declare function resetWarned(): void;
  22. export declare function call(method: (valid: boolean, message: string) => void, valid: boolean, message: string): void;
  23. /** @see Same as {@link warning}, but only warn once for the same message */
  24. export declare function warningOnce(valid: boolean, message: string): void;
  25. export declare namespace warningOnce {
  26. var preMessage: (fn: preMessageFn) => void;
  27. var resetWarned: typeof import("./warning").resetWarned;
  28. var noteOnce: typeof import("./warning").noteOnce;
  29. }
  30. /** @see Same as {@link warning}, but only warn once for the same message */
  31. export declare function noteOnce(valid: boolean, message: string): void;
  32. export default warningOnce;