@@ -6,22 +6,41 @@ import { doAction } from '@wordpress/hooks';
6
6
/**
7
7
* Object map tracking messages which have been logged, for use in ensuring a
8
8
* message is only logged once.
9
- *
10
- * @type {Record<string, true | undefined> }
11
9
*/
12
- export const logged = Object . create ( null ) ;
10
+ export const logged : Record < string , true > = Object . create ( null ) ;
11
+
12
+ type DeprecatedOptions = {
13
+ /**
14
+ * Version in which the feature was deprecated.
15
+ */
16
+ since ?: string ;
17
+ /**
18
+ * Version in which the feature will be removed.
19
+ */
20
+ version ?: string ;
21
+ /**
22
+ * Feature to use instead.
23
+ */
24
+ alternative ?: string ;
25
+ /**
26
+ * Plugin name if it's a plugin feature.
27
+ */
28
+ plugin ?: string ;
29
+ /**
30
+ * Link to documentation.
31
+ */
32
+ link ?: string ;
33
+ /**
34
+ * Additional message to help transition away from the deprecated feature.
35
+ */
36
+ hint ?: string ;
37
+ } ;
13
38
14
39
/**
15
40
* Logs a message to notify developers about a deprecated feature.
16
41
*
17
- * @param {string } feature Name of the deprecated feature.
18
- * @param {Object } [options] Personalisation options
19
- * @param {string } [options.since] Version in which the feature was deprecated.
20
- * @param {string } [options.version] Version in which the feature will be removed.
21
- * @param {string } [options.alternative] Feature to use instead
22
- * @param {string } [options.plugin] Plugin name if it's a plugin feature
23
- * @param {string } [options.link] Link to documentation
24
- * @param {string } [options.hint] Additional message to help transition away from the deprecated feature.
42
+ * @param {string } feature Name of the deprecated feature.
43
+ * @param {DeprecatedOptions } [options] Personalisation options
25
44
*
26
45
* @example
27
46
* ```js
@@ -38,7 +57,10 @@ export const logged = Object.create( null );
38
57
* // Logs: 'Eating meat is deprecated since version 2019.01.01 and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
39
58
* ```
40
59
*/
41
- export default function deprecated ( feature , options = { } ) {
60
+ export default function deprecated (
61
+ feature : string ,
62
+ options : DeprecatedOptions = { }
63
+ ) {
42
64
const { since, version, alternative, plugin, link, hint } = options ;
43
65
44
66
const pluginMessage = plugin ? ` from ${ plugin } ` : '' ;
@@ -61,15 +83,9 @@ export default function deprecated( feature, options = {} ) {
61
83
/**
62
84
* Fires whenever a deprecated feature is encountered
63
85
*
64
- * @param {string } feature Name of the deprecated feature.
65
- * @param {?Object } options Personalisation options
66
- * @param {string } options.since Version in which the feature was deprecated.
67
- * @param {?string } options.version Version in which the feature will be removed.
68
- * @param {?string } options.alternative Feature to use instead
69
- * @param {?string } options.plugin Plugin name if it's a plugin feature
70
- * @param {?string } options.link Link to documentation
71
- * @param {?string } options.hint Additional message to help transition away from the deprecated feature.
72
- * @param {?string } message Message sent to console.warn
86
+ * @param {string } feature Name of the deprecated feature.
87
+ * @param {DeprecatedOptions } options Personalisation options
88
+ * @param {string } message Message sent to console.warn
73
89
*/
74
90
doAction ( 'deprecated' , feature , options , message ) ;
75
91
@@ -78,5 +94,3 @@ export default function deprecated( feature, options = {} ) {
78
94
79
95
logged [ message ] = true ;
80
96
}
81
-
82
- /** @typedef {import('utility-types').NonUndefined<Parameters<typeof deprecated>[1]> } DeprecatedOptions */
0 commit comments