[@wordpress/deprecated] add new definitions (#36684)

This commit is contained in:
Derek Sifford 2019-07-10 19:10:51 -04:00 committed by Armando Aguirre
parent 0f4a6a3b3a
commit ae6aa49a5f
4 changed files with 94 additions and 0 deletions

57
types/wordpress__deprecated/index.d.ts vendored Normal file
View File

@ -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 <https://github.com/dsifford>
// 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<string, boolean | undefined>;
/**
* 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;

View File

@ -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"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@ -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<string, boolean | undefined>
logged;
// $ExpectType boolean | undefined
logged.foo;