Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typings relating to requestAsEventEmitter #760

Merged

Conversation

paulmelnikow
Copy link
Contributor

@paulmelnikow paulmelnikow commented Mar 22, 2019

This improves several of the types in requestAsEventEmitter, including its own return type and its dependencies. It also clears several TypeScript warnings.

There are several changes which convert

import http from 'http'

to

import * as fs from 'fs'

This is to clear warnings which look like this:

source/utils/get-body-size.ts:1:8 - error TS1192: Module '"fs"' has no default export.

1 import fs from 'fs';

My workflow has primarily to run ./node_modules/.bin/tsc --noEmit source/request-as-event-emitter.ts and then the tests. I'm not sure if there is a better way to evaluate the changes to the types.

This is my first PR on got. I'm not an expert in TypeScript and there are definitely some good challenges here! Looking forward to feedback.

Checklist

  • I have read the documentation.
  • I have included a pull request description of my changes.
  • I have included some tests.
  • If it's a new feature, I have included documentation updates.

Ref: #758

source/utils/types.ts Outdated Show resolved Hide resolved
source/utils/types.ts Show resolved Hide resolved
@sindresorhus
Copy link
Owner

There are several changes which convert

You should not need to do changes like these. We have the allowSyntheticDefaultImports config enabled. Seems you're not picking up our tsconfig for some reason.

@paulmelnikow
Copy link
Contributor Author

paulmelnikow commented Mar 23, 2019

You should not need to do changes like these. We have the allowSyntheticDefaultImports config enabled. Seems you're not picking up our tsconfig for some reason.

That makes sense; I'll revert them. Though it's odd that tsc isn't picking up the tsconfig correctly.

Added: Ah, I guess this is the expected behavior when specifying input files to tsc.

paulmelnikow added a commit to paulmelnikow/DefinitelyTyped that referenced this pull request Mar 24, 2019
This allows easily declaring a parameter that will be passed into the
constructor.

Ref sindresorhus/got#760 (comment)
paulmelnikow added a commit to paulmelnikow/DefinitelyTyped that referenced this pull request Mar 24, 2019
This allows easily declaring a parameter that will be passed into the
constructor.

Ref sindresorhus/got#760 (comment)
source/utils/types.ts Outdated Show resolved Hide resolved
source/utils/types.ts Outdated Show resolved Hide resolved
source/utils/types.ts Outdated Show resolved Hide resolved
sheetalkamat pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Mar 25, 2019
* [cacheable-request] Include type alias for cache adapter

This allows easily declaring a parameter that will be passed into the
constructor.

Ref sindresorhus/got#760 (comment)

* Fix missing semicolon

* Move StorageAdapter into namespace
if (options.useElectronNet && (process.versions as any).electron) {
// @ts-ignore
const r = ({x: require})['yx'.slice(1)]; // Trick webpack
const electron = r('electron');
fn = electron.net || electron.remote.net;
requestFn = electron.net || electron.remote.net;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests for this code? I realize this was not accessing electron.net.request as it should.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, too much overhead to include Electron testing to be worth it. We do manual test after doing changes to that code.

timolinn pushed a commit to timolinn/DefinitelyTyped that referenced this pull request Mar 26, 2019
…yped#34155)

* [cacheable-request] Include type alias for cache adapter

This allows easily declaring a parameter that will be passed into the
constructor.

Ref sindresorhus/got#760 (comment)

* Fix missing semicolon

* Move StorageAdapter into namespace
@sindresorhus
Copy link
Owner

@paulmelnikow Is this good to merge or do you intend to do more changes?

@sindresorhus sindresorhus mentioned this pull request Mar 28, 2019
4 tasks
@paulmelnikow
Copy link
Contributor Author

Good to merge!

@sindresorhus sindresorhus merged commit aac0792 into sindresorhus:master Mar 28, 2019
@sindresorhus
Copy link
Owner

Thank you! 🙏

@paulmelnikow
Copy link
Contributor Author

Thanks for all the comments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants