mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Merge pull request #25737 from VincentLanglet/react-native/fetch
[react-native] Add missing GlobalFetch / RequestInfo definitions
This commit is contained in:
8
types/react-native/globals.d.ts
vendored
8
types/react-native/globals.d.ts
vendored
@@ -25,7 +25,11 @@ declare function fetchBundle(bundleId: number, callback: (error?: Error | null)
|
||||
// Fetch API
|
||||
//
|
||||
|
||||
declare function fetch(input: Request | string, init?: RequestInit): Promise<Response>;
|
||||
declare interface GlobalFetch {
|
||||
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
||||
}
|
||||
|
||||
declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
||||
|
||||
interface Blob {}
|
||||
|
||||
@@ -85,6 +89,8 @@ declare var Request: {
|
||||
new(input: Request | string, init?: RequestInit): Request;
|
||||
};
|
||||
|
||||
declare type RequestInfo = Request | string;
|
||||
|
||||
declare interface ResponseInit {
|
||||
headers?: HeadersInit_;
|
||||
status?: number;
|
||||
|
||||
26
types/react-native/test/globals.tsx
Normal file
26
types/react-native/test/globals.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
const fetchCopy: GlobalFetch['fetch'] = fetch;
|
||||
|
||||
const myHeaders = new Headers();
|
||||
myHeaders.append('Content-Type', 'image/jpeg');
|
||||
|
||||
const myInit: RequestInit = {
|
||||
method: 'GET',
|
||||
headers: myHeaders,
|
||||
mode: 'cors',
|
||||
};
|
||||
|
||||
const myRequest = new Request('flowers.jpg');
|
||||
|
||||
fetch(myRequest, myInit).then((response) => {
|
||||
console.log(response.type);
|
||||
console.log(response.url);
|
||||
console.log(response.status);
|
||||
console.log(response.ok);
|
||||
console.log(response.statusText);
|
||||
console.log(response.headers);
|
||||
|
||||
return response.blob();
|
||||
}).then((blob) => {
|
||||
const init = { status: 200, statusText: 'SuperSmashingGreat!' }
|
||||
const myResponse = new Response(blob, init);
|
||||
})
|
||||
@@ -20,9 +20,10 @@
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"test/index.tsx",
|
||||
"test/globals.tsx",
|
||||
"test/animated.tsx",
|
||||
"test/init-example.tsx",
|
||||
"test/ART.tsx",
|
||||
"test/legacy-properties.tsx"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user