diff --git a/types/wordpress__deprecated/index.d.ts b/types/wordpress__deprecated/index.d.ts new file mode 100644 index 0000000000..cf4cc12105 --- /dev/null +++ b/types/wordpress__deprecated/index.d.ts @@ -0,0 +1,57 @@ +// Type definitions for @wordpress/deprecated 2.4 +// Project: https://github.com/WordPress/gutenberg/tree/master/packages/deprecated/README.md +// Definitions by: Derek Sifford +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.5 + +export interface DeprecatedOptions { + /** + * Feature to use instead. + */ + alternative?: string; + /** + * Additional message to help transition away from the deprecated feature. + */ + hint?: string; + /** + * Link to documentation. + */ + link?: string; + /** + * Plugin name if it's a plugin feature. + */ + plugin?: string; + /** + * Version in which the feature will be removed. + */ + version?: string; +} + +/** + * Object map tracking messages which have been logged, for use in ensuring a message is only logged once. + */ +export const logged: Record; + +/** + * Logs a message to notify developers about a deprecated feature. + * + * @param feature Name of the deprecated feature. + * @param [options] Additional options. + * + * @example + * ```js + * import deprecated from '@wordpress/deprecated'; + * + * deprecated( 'Eating meat', { + * version: 'the future', + * alternative: 'vegetables', + * plugin: 'the earth', + * hint: 'You may find it beneficial to transition gradually.', + * } ); + * + * // Logs: 'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. Note: You may find it beneficial to transition gradually.' + * ``` + */ +declare function deprecated(feature: string, options?: DeprecatedOptions): void; + +export default deprecated; diff --git a/types/wordpress__deprecated/tsconfig.json b/types/wordpress__deprecated/tsconfig.json new file mode 100644 index 0000000000..d8cb525556 --- /dev/null +++ b/types/wordpress__deprecated/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@wordpress/deprecated": ["wordpress__deprecated"] + } + }, + "files": ["index.d.ts", "wordpress__deprecated-tests.ts"] +} diff --git a/types/wordpress__deprecated/tslint.json b/types/wordpress__deprecated/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wordpress__deprecated/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wordpress__deprecated/wordpress__deprecated-tests.ts b/types/wordpress__deprecated/wordpress__deprecated-tests.ts new file mode 100644 index 0000000000..f74ebdec31 --- /dev/null +++ b/types/wordpress__deprecated/wordpress__deprecated-tests.ts @@ -0,0 +1,17 @@ +import deprecated, { logged } from '@wordpress/deprecated'; + +// $ExpectType void +deprecated('foo'); + +deprecated('foo', { alternative: 'bar' }); +deprecated('foo', { hint: 'bar' }); +deprecated('foo', { link: 'bar' }); +deprecated('foo', { plugin: 'bar' }); +deprecated('foo', { version: 'bar' }); +deprecated('foo', { alternative: 'bar', hint: 'baz', version: 'qux' }); + +// $ExpectType Record +logged; + +// $ExpectType boolean | undefined +logged.foo;