Skip to content

Commit 1c18883

Browse files
committed
fix TypeScript types
1 parent 93c3284 commit 1c18883

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/index.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
/**
6868
* @public
69-
* @param {Options} [defaults]
69+
* @param {Options} [defaults = {}]
7070
* @returns {redaxios}
7171
*/
7272
function create(defaults) {
@@ -113,15 +113,17 @@ function create(defaults) {
113113

114114
/**
115115
* @private
116-
* @param {Record<string,any>} opts
117-
* @param {Record<string,any>} [overrides]
116+
* @template T, U
117+
* @param {T} opts
118+
* @param {U} [overrides]
118119
* @param {boolean} [lowerCase]
119-
* @returns {Partial<opts>}
120+
* @returns {{} & (T | U)}
120121
*/
121122
function deepMerge(opts, overrides, lowerCase) {
122-
let out = {},
123+
let out = /** @type {any} */ ({}),
123124
i;
124125
if (Array.isArray(opts)) {
126+
// @ts-ignore
125127
return opts.concat(overrides);
126128
}
127129
for (i in opts) {
@@ -140,18 +142,15 @@ function create(defaults) {
140142
* Issues a request.
141143
* @public
142144
* @template T
143-
* @param {string | Options} url
144-
* @param {Options} [config]
145+
* @param {string | Options} urlOrConfig
146+
* @param {Options} [config = {}]
145147
* @param {any} [_method] (internal)
146148
* @param {any} [data] (internal)
147149
* @param {never} [_undefined] (internal)
148150
* @returns {Promise<Response<T>>}
149151
*/
150-
function redaxios(url, config, _method, data, _undefined) {
151-
if (typeof url !== 'string') {
152-
config = url;
153-
url = config.url;
154-
}
152+
function redaxios(urlOrConfig, config, _method, data, _undefined) {
153+
let url = /** @type {string} */ (typeof urlOrConfig != 'string' ? (config = urlOrConfig).url : urlOrConfig);
155154

156155
const response = /** @type {Response<any>} */ ({ config });
157156

@@ -177,7 +176,9 @@ function create(defaults) {
177176
}
178177

179178
try {
179+
// @ts-ignore providing the cookie name without header name is nonsensical anyway
180180
customHeaders[options.xsrfHeaderName] = decodeURIComponent(
181+
// @ts-ignore accessing match()[2] throws for no match, which is intentional
181182
document.cookie.match(RegExp('(^|; )' + options.xsrfCookieName + '=([^;]*)'))[2]
182183
);
183184
} catch (e) {}

0 commit comments

Comments
 (0)