mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
[@wordpress/api-fetch] Remove DT definitions (#52388)
Co-authored-by: Orta <git@orta.io>
This commit is contained in:
@@ -5302,6 +5302,10 @@
|
||||
"libraryName": "@wordpress/a11y",
|
||||
"asOfVersion": "2.9.0"
|
||||
},
|
||||
"wordpress__api-fetch": {
|
||||
"libraryName": "@wordpress/api-fetch",
|
||||
"asOfVersion": "3.23.1"
|
||||
},
|
||||
"wordpress__autop": {
|
||||
"libraryName": "@wordpress/autop",
|
||||
"asOfVersion": "2.7.0"
|
||||
|
||||
60
types/wordpress__api-fetch/index.d.ts
vendored
60
types/wordpress__api-fetch/index.d.ts
vendored
@@ -1,60 +0,0 @@
|
||||
// Type definitions for @wordpress/api-fetch 3.2
|
||||
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/api-fetch/README.md
|
||||
// Definitions by: Derek Sifford <https://github.com/dsifford>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.6
|
||||
|
||||
export interface APIFetchOptions extends RequestInit {
|
||||
/**
|
||||
* Shorthand to be used in place of url, appended to the REST API root URL
|
||||
* for the current site.
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* Absolute URL to the endpoint from which to fetch.
|
||||
*/
|
||||
url?: string;
|
||||
/**
|
||||
* Unlike `fetch`, the `Promise` return value of `apiFetch` will resolve to the
|
||||
* parsed JSON result. Disable this behavior by passing `parse` as `false`.
|
||||
*
|
||||
* @defaultValue true
|
||||
*/
|
||||
parse?: boolean;
|
||||
/**
|
||||
* Shorthand to be used in place of body, accepts an object value to be
|
||||
* stringified to JSON.
|
||||
*/
|
||||
data?: object;
|
||||
}
|
||||
|
||||
export type Middleware = (options: APIFetchOptions, next: (options: APIFetchOptions) => Promise<any>) => Promise<any>;
|
||||
|
||||
declare namespace apiFetch {
|
||||
function use(middleware: Middleware): void;
|
||||
/**
|
||||
* The `api-fetch` package uses `window.fetch` for making the requests but you
|
||||
* can use a custom fetch handler by using the `setFetchHandler` method. The
|
||||
* custom fetch handler will receive the `options` passed to the `apiFetch`
|
||||
* calls.
|
||||
*/
|
||||
function setFetchHandler(handler: (options: APIFetchOptions) => PromiseLike<any>): void;
|
||||
|
||||
//
|
||||
// Built-in middleware
|
||||
//
|
||||
|
||||
/**
|
||||
* The function returned by `createNonceMiddleware` includes a `nonce` property
|
||||
* corresponding to the actively used nonce. You may also assign to this
|
||||
* property if you have a fresh nonce value to use.
|
||||
*/
|
||||
function createNonceMiddleware(nonce: string): Middleware;
|
||||
function createPreloadingMiddleware(data: Record<string, any>): Middleware;
|
||||
function createRootURLMiddleware(rootUrl: string): Middleware;
|
||||
const fetchAllMiddleware: Middleware;
|
||||
}
|
||||
|
||||
declare function apiFetch(options: APIFetchOptions & { parse: false }): Promise<Response>;
|
||||
declare function apiFetch<T = unknown>(options: APIFetchOptions): Promise<T>; // tslint:disable-line no-unnecessary-generics
|
||||
export default apiFetch;
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6", "dom"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@wordpress/*": ["wordpress__*"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "wordpress__api-fetch-tests.ts"]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -1,29 +0,0 @@
|
||||
import { Schema } from '@wordpress/core-data';
|
||||
import apiFetch, { Middleware } from '@wordpress/api-fetch';
|
||||
|
||||
async function foo() {
|
||||
apiFetch<Schema.Post[]>({ path: '/wp/v2/posts' }).then(posts =>
|
||||
posts.map(({ date, title }) => `Post "${title.rendered}" at ${date}`)
|
||||
);
|
||||
const response = await apiFetch({ parse: false });
|
||||
if (response.ok) {
|
||||
console.log(await response.json());
|
||||
}
|
||||
}
|
||||
|
||||
const x: Middleware = async (undefined, next) => {
|
||||
const x = await next({});
|
||||
return next({});
|
||||
};
|
||||
|
||||
apiFetch.use(apiFetch.fetchAllMiddleware);
|
||||
apiFetch.use(apiFetch.createRootURLMiddleware('https://foo.bar/wp-json'));
|
||||
|
||||
apiFetch.setFetchHandler(options => {
|
||||
const { url, path, data, method } = options;
|
||||
|
||||
return fetch(url || path || '', {
|
||||
method,
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
});
|
||||
2
types/wordpress__data-controls/index.d.ts
vendored
2
types/wordpress__data-controls/index.d.ts
vendored
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/data-controls/README.md
|
||||
// Definitions by: Derek Sifford <https://github.com/dsifford>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.6
|
||||
// TypeScript Version: 3.7
|
||||
|
||||
import { APIFetchOptions } from '@wordpress/api-fetch';
|
||||
import { Action } from '@wordpress/data';
|
||||
|
||||
6
types/wordpress__data-controls/package.json
Normal file
6
types/wordpress__data-controls/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@wordpress/api-fetch": "^3.23.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user