mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 02:46:04 +01:00 
			
		
		
		
	Add types to fetch,toast,bootstrap,svg (#31627)
Reduce `tsc` error count by 53. None of the changes has any runtime effect.
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| import {isObject} from '../utils.ts'; | ||||
| import type {RequestData, RequestOpts} from '../types.ts'; | ||||
|  | ||||
| const {csrfToken} = window.config; | ||||
|  | ||||
| @@ -8,8 +9,9 @@ const safeMethods = new Set(['GET', 'HEAD', 'OPTIONS', 'TRACE']); | ||||
| // fetch wrapper, use below method name functions and the `data` option to pass in data | ||||
| // which will automatically set an appropriate headers. For json content, only object | ||||
| // and array types are currently supported. | ||||
| export function request(url, {method = 'GET', data, headers = {}, ...other} = {}) { | ||||
|   let body, contentType; | ||||
| export function request(url: string, {method = 'GET', data, headers = {}, ...other}: RequestOpts = {}) { | ||||
|   let body: RequestData; | ||||
|   let contentType: string; | ||||
|   if (data instanceof FormData || data instanceof URLSearchParams) { | ||||
|     body = data; | ||||
|   } else if (isObject(data) || Array.isArray(data)) { | ||||
| @@ -34,8 +36,8 @@ export function request(url, {method = 'GET', data, headers = {}, ...other} = {} | ||||
|   }); | ||||
| } | ||||
|  | ||||
| export const GET = (url, opts) => request(url, {method: 'GET', ...opts}); | ||||
| export const POST = (url, opts) => request(url, {method: 'POST', ...opts}); | ||||
| export const PATCH = (url, opts) => request(url, {method: 'PATCH', ...opts}); | ||||
| export const PUT = (url, opts) => request(url, {method: 'PUT', ...opts}); | ||||
| export const DELETE = (url, opts) => request(url, {method: 'DELETE', ...opts}); | ||||
| export const GET = (url: string, opts?: RequestOpts) => request(url, {method: 'GET', ...opts}); | ||||
| export const POST = (url: string, opts?: RequestOpts) => request(url, {method: 'POST', ...opts}); | ||||
| export const PATCH = (url: string, opts?: RequestOpts) => request(url, {method: 'PATCH', ...opts}); | ||||
| export const PUT = (url: string, opts?: RequestOpts) => request(url, {method: 'PUT', ...opts}); | ||||
| export const DELETE = (url: string, opts?: RequestOpts) => request(url, {method: 'DELETE', ...opts}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user