Skip to content

Commit b51d836

Browse files
authored
Upgrade to TypeScript 3.9 (#1267)
1 parent ed897d7 commit b51d836

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"node": ">=10.19.0"
1111
},
1212
"scripts": {
13-
"test": "xo && tsc --noEmit && nyc --reporter=html --reporter=text ava",
13+
"test": "xo && npm run build && nyc --reporter=html --reporter=text ava",
1414
"release": "np",
1515
"build": "del-cli dist && tsc",
1616
"prepare": "npm run build"
@@ -61,7 +61,7 @@
6161
"@sinonjs/fake-timers": "^6.0.1",
6262
"@types/benchmark": "^1.0.31",
6363
"@types/express": "^4.17.6",
64-
"@types/node": "^13.13.4",
64+
"@types/node": "^14.0.11",
6565
"@types/node-fetch": "^2.5.5",
6666
"@types/request": "^2.48.4",
6767
"@types/sinon": "^9.0.0",
@@ -86,7 +86,7 @@
8686
"tempy": "^0.5.0",
8787
"to-readable-stream": "^2.1.0",
8888
"tough-cookie": "^4.0.0",
89-
"typescript": "3.8.3",
89+
"typescript": "3.9.6",
9090
"xo": "^0.30.0"
9191
},
9292
"types": "dist/source",

source/as-promise/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (!knownHookEvents.includes('beforeRetry' as any)) {
2222
export const knownBodyTypes = ['json', 'buffer', 'text'];
2323

2424
// @ts-ignore The error is: Not all code paths return a value.
25-
export const parseBody = (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: string): unknown => {
25+
export const parseBody = (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: BufferEncoding): unknown => {
2626
const {rawBody} = response;
2727

2828
try {

source/core/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
13381338
this._unlockWrite();
13391339

13401340
if (!is.undefined(body)) {
1341-
this._writeRequest(body, null as unknown as string, () => {});
1341+
this._writeRequest(body, undefined, () => {});
13421342
currentRequest.end();
13431343

13441344
this._lockWrite();
@@ -1604,7 +1604,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
16041604
}
16051605
}
16061606

1607-
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void {
1607+
_write(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void {
16081608
const write = (): void => {
16091609
this._writeRequest(chunk, encoding, callback);
16101610
};
@@ -1616,9 +1616,9 @@ export default class Request extends Duplex implements RequestEvents<Request> {
16161616
}
16171617
}
16181618

1619-
_writeRequest(chunk: any, encoding: string, callback: (error?: Error | null) => void): void {
1619+
_writeRequest(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void {
16201620
this._progressCallbacks.push((): void => {
1621-
this[kUploadedSize] += Buffer.byteLength(chunk, encoding as BufferEncoding);
1621+
this[kUploadedSize] += Buffer.byteLength(chunk, encoding);
16221622

16231623
const progress = this.uploadProgress;
16241624

@@ -1629,7 +1629,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
16291629

16301630
// TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
16311631

1632-
this[kRequest]!.write(chunk, encoding, (error?: Error | null) => {
1632+
this[kRequest]!.write(chunk, encoding!, (error?: Error | null) => {
16331633
if (!error && this._progressCallbacks.length !== 0) {
16341634
this._progressCallbacks.shift()!();
16351635
}

source/create.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ const create = (defaults: InstanceDefaults): Got => {
120120
) as GotReturn;
121121
};
122122

123-
// TODO: remove this in Got 12
123+
// TODO: Remove this in Got 12.
124124
if (is.plainObject(url)) {
125125
const mergedOptions = {
126126
...url as Options,
127127
...options
128128
};
129129

130-
setNonEnumerableProperties([url, options], mergedOptions);
130+
setNonEnumerableProperties([url as Options, options], mergedOptions);
131131

132132
options = mergedOptions;
133133
url = undefined as any;
@@ -197,6 +197,9 @@ const create = (defaults: InstanceDefaults): Got => {
197197

198198
// Pagination
199199
const paginateEach = (async function * <T, R>(url: string | URL, options?: OptionsWithPagination<T, R>) {
200+
// TODO: Remove this `@ts-expect-error` when upgrading to TypeScript 4.
201+
// Error: Argument of type 'Merge<Options, PaginationOptions<T, R>> | undefined' is not assignable to parameter of type 'Options | undefined'.
202+
// @ts-expect-error
200203
let normalizedOptions = normalizeArguments(url, options, defaults.options);
201204
normalizedOptions.resolveBodyOnly = false;
202205

source/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export default got;
125125
// For CommonJS default export support
126126
module.exports = got;
127127
module.exports.default = got;
128+
module.exports.__esModule = true; // Workaround for TS issue: https://github.com/sindresorhus/got/pull/1267
128129

129130
export * from './create';
130131
export * from './as-promise';

0 commit comments

Comments
 (0)