Skip to content

Commit

Permalink
Upgrade to TypeScript 3.9 (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus authored Jul 5, 2020
1 parent ed897d7 commit b51d836
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": ">=10.19.0"
},
"scripts": {
"test": "xo && tsc --noEmit && nyc --reporter=html --reporter=text ava",
"test": "xo && npm run build && nyc --reporter=html --reporter=text ava",
"release": "np",
"build": "del-cli dist && tsc",
"prepare": "npm run build"
Expand Down Expand Up @@ -61,7 +61,7 @@
"@sinonjs/fake-timers": "^6.0.1",
"@types/benchmark": "^1.0.31",
"@types/express": "^4.17.6",
"@types/node": "^13.13.4",
"@types/node": "^14.0.11",
"@types/node-fetch": "^2.5.5",
"@types/request": "^2.48.4",
"@types/sinon": "^9.0.0",
Expand All @@ -86,7 +86,7 @@
"tempy": "^0.5.0",
"to-readable-stream": "^2.1.0",
"tough-cookie": "^4.0.0",
"typescript": "3.8.3",
"typescript": "3.9.6",
"xo": "^0.30.0"
},
"types": "dist/source",
Expand Down
2 changes: 1 addition & 1 deletion source/as-promise/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (!knownHookEvents.includes('beforeRetry' as any)) {
export const knownBodyTypes = ['json', 'buffer', 'text'];

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

try {
Expand Down
10 changes: 5 additions & 5 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
this._unlockWrite();

if (!is.undefined(body)) {
this._writeRequest(body, null as unknown as string, () => {});
this._writeRequest(body, undefined, () => {});
currentRequest.end();

this._lockWrite();
Expand Down Expand Up @@ -1604,7 +1604,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
}
}

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

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

const progress = this.uploadProgress;

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

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

this[kRequest]!.write(chunk, encoding, (error?: Error | null) => {
this[kRequest]!.write(chunk, encoding!, (error?: Error | null) => {
if (!error && this._progressCallbacks.length !== 0) {
this._progressCallbacks.shift()!();
}
Expand Down
7 changes: 5 additions & 2 deletions source/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ const create = (defaults: InstanceDefaults): Got => {
) as GotReturn;
};

// TODO: remove this in Got 12
// TODO: Remove this in Got 12.
if (is.plainObject(url)) {
const mergedOptions = {
...url as Options,
...options
};

setNonEnumerableProperties([url, options], mergedOptions);
setNonEnumerableProperties([url as Options, options], mergedOptions);

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

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

Expand Down
1 change: 1 addition & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default got;
// For CommonJS default export support
module.exports = got;
module.exports.default = got;
module.exports.__esModule = true; // Workaround for TS issue: https://github.com/sindresorhus/got/pull/1267

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

0 comments on commit b51d836

Please sign in to comment.