1 | declare module '@ember/debug/lib/deprecate' {
|
2 | import type { HandlerCallback } from '@ember/debug/lib/handlers';
|
3 | interface Available {
|
4 | available: string;
|
5 | }
|
6 | interface Enabled extends Available {
|
7 | enabled: string;
|
8 | }
|
9 | export interface DeprecationOptions {
|
10 | id: string;
|
11 | until: string;
|
12 | url?: string;
|
13 | for: string;
|
14 | since: Available | Enabled;
|
15 | }
|
16 | export type DeprecateFunc = (
|
17 | message: string,
|
18 | test?: boolean,
|
19 | options?: DeprecationOptions
|
20 | ) => void;
|
21 | export type MissingOptionDeprecateFunc = (id: string, missingOption: string) => string;
|
22 | /**
|
23 | @module @ember/debug
|
24 | @public
|
25 | */
|
26 | /**
|
27 | Allows for runtime registration of handler functions that override the default deprecation behavior.
|
28 | Deprecations are invoked by calls to [@ember/debug/deprecate](/ember/release/classes/@ember%2Fdebug/methods/deprecate?anchor=deprecate).
|
29 | The following example demonstrates its usage by registering a handler that throws an error if the
|
30 | message contains the word "should", otherwise defers to the default handler.
|
31 |
|
32 | ```javascript
|
33 | import { registerDeprecationHandler } from '@ember/debug';
|
34 |
|
35 | registerDeprecationHandler((message, options, next) => {
|
36 | if (message.indexOf('should') !== -1) {
|
37 | throw new Error(`Deprecation message with should: ${message}`);
|
38 | } else {
|
39 | // defer to whatever handler was registered before this one
|
40 | next(message, options);
|
41 | }
|
42 | });
|
43 | ```
|
44 |
|
45 | The handler function takes the following arguments:
|
46 |
|
47 | <ul>
|
48 | <li> <code>message</code> - The message received from the deprecation call.</li>
|
49 | <li> <code>options</code> - An object passed in with the deprecation call containing additional information including:</li>
|
50 | <ul>
|
51 | <li> <code>id</code> - An id of the deprecation in the form of <code>package-name.specific-deprecation</code>.</li>
|
52 | <li> <code>until</code> - The Ember version number the feature and deprecation will be removed in.</li>
|
53 | </ul>
|
54 | <li> <code>next</code> - A function that calls into the previously registered handler.</li>
|
55 | </ul>
|
56 |
|
57 | @public
|
58 | @static
|
59 | @method registerDeprecationHandler
|
60 | @for @ember/debug
|
61 | @param handler {Function} A function to handle deprecation calls.
|
62 | @since 2.1.0
|
63 | */
|
64 | let registerHandler: (handler: HandlerCallback<DeprecationOptions>) => void;
|
65 | let missingOptionsDeprecation: string;
|
66 | let missingOptionsIdDeprecation: string;
|
67 | let missingOptionDeprecation: MissingOptionDeprecateFunc;
|
68 | let deprecate: DeprecateFunc;
|
69 | export default deprecate;
|
70 | export {
|
71 | registerHandler,
|
72 | missingOptionsDeprecation,
|
73 | missingOptionsIdDeprecation,
|
74 | missingOptionDeprecation,
|
75 | };
|
76 | }
|