mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
wpapi: class support custom methods though without return type
This commit is contained in:
Vendored
+14
-3
@@ -27,9 +27,6 @@ declare class WPAPI {
|
||||
*/
|
||||
static discover(url: string): Promise<WPAPI>;
|
||||
|
||||
/** Start a request of plugin authors endpoint */
|
||||
authors(): WPAPI.WPRequest;
|
||||
|
||||
/** Start a request against /categories endpoint */
|
||||
categories(): WPAPI.WPRequest;
|
||||
|
||||
@@ -163,6 +160,13 @@ declare class WPAPI {
|
||||
* @param url The URL to request
|
||||
*/
|
||||
url(url: string): WPAPI.WPRequest;
|
||||
|
||||
/**
|
||||
* An API client can define its parameter methods, like .authors(), .cart(),
|
||||
* .products(). They are usually decided by WPAPI namespaces configuration
|
||||
* object. They have WPRequest return type.
|
||||
*/
|
||||
[customRoutesMethod: string]: any;
|
||||
}
|
||||
|
||||
/*~ If you want to expose types from your module as well, you can
|
||||
@@ -411,6 +415,13 @@ declare namespace WPAPI {
|
||||
* the regular expression the API uses to goven that segment.
|
||||
*/
|
||||
validatePath(): WPRequest;
|
||||
|
||||
/**
|
||||
* A request can define its parameter methods, like .id(), .date(),
|
||||
* .author(). They are usually decided by WPAPI routes configuration
|
||||
* object.
|
||||
*/
|
||||
[customParamsMethod: string]: any;
|
||||
}
|
||||
|
||||
export interface WPAPIOptions extends Credentials {
|
||||
|
||||
@@ -28,19 +28,21 @@ apiPromise.then(site => {
|
||||
site.posts().then((posts: Object[]) => {}); // etc
|
||||
|
||||
// If custom routes were detected, they can be accessed via .namespace()
|
||||
site
|
||||
.namespace("myplugin/v1")
|
||||
.authors()
|
||||
.then((authors: Object[]) => {
|
||||
// Custom routes have different methods to generate requests, so .authors()
|
||||
// does not necessarily exist. You have use force type <WPRequest> or 'as
|
||||
// Request'
|
||||
(site.namespace("myplugin/v1").authors() as WPAPI.WPRequest).then(
|
||||
(authors: any[]) => {
|
||||
/* ... */
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Namespaces can be saved out to variables:
|
||||
const myplugin = site.namespace("myplugin/v1");
|
||||
myplugin
|
||||
.authors()
|
||||
.id(7)
|
||||
.then((author: Object[]) => {
|
||||
.then((author: any) => {
|
||||
/* ... */
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user