Skip to content

Conversation

@SimonSchick
Copy link
Contributor

I changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: Does not apply
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

This applies most lint rules, except ones that would introduce too many breaking changes.
The main changes here are:

  • Removal of almost all export keywords (http2 is a special case)
  • line lengths (ugh)
  • removals of generic that the linter didn't like, this might cause some issues but ideally shouldn't.
  • All values are not const instead of var, this might be debatable because some may re-write globals, please advise.

This (for now) includes #29147

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Sep 24, 2018
@typescript-bot
Copy link
Contributor

typescript-bot commented Sep 24, 2018

@SimonSchick Thank you for submitting this PR!

🔔 @joeskeen @aznnomness @cspotcode @chrootsu @jeffmay @basarat @barbatus @fullflavedave @orefalo @dagatsoin @birkskyum @ardatan @stefanholzapfel @andrei-markeev @lmachens @parambirs @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk @wwwy3y3 @DeividasBakanas @kjin @alvis @eps1lon @Hannes-Magnusson-CK @jkomyno @ajafff @hoo29 @n-e @BrunoScheufler @mohsen1 @KSXGitHub @a-tarasyuk @islishude @r3nya @ZaneHannanAU @ThomasdenH @eyqs @matthieusieben @Morfent @nonAlgebraic @wokim @heycalmdown @stevehipwell @nickiannone @ashleybrener - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@SimonSchick
Copy link
Contributor Author

Note: Changes caused some other packages to fail, is there any way to test this locally @basarat ?
Notable changes in other packages:
Removed console declaration of meteor since that appears to conflict.
Removed undefined from ParsedUrlQuery as according to the docs this is not even possible.
Add cast to grunt as it's being a special snowflake.

@SimonSchick
Copy link
Contributor Author

Another update:
Removed ServerRequest and ClientResponse as these classes do not exist anymore.
Removed runInDebugContext as it was removed.

@typescript-bot
Copy link
Contributor

@SimonSchick The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@typescript-bot
Copy link
Contributor

@SimonSchick The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

maxKeys?: number;
decodeURIComponent?: Function;
}

interface ParsedUrlQuery { [key: string]: string | string[] | undefined; }
interface ParsedUrlQuery { [key: string]: string | string[]; }
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason why | undefined was used here is that this allows you to augment ParsedUrlQuery like this in your application to easier access properties:

  my_key?: string,
  my_arr_key?: string[]
}

if | undefined is not there it's only possible to specify mandatory properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not following, can you provide an example maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

        let result: querystring.ParsedUrlQuery;

        const a: {
            a?: string;
        } = result;

works just fine in this case (pulled from test).

If you are talking about augmenting the interface through declaration merging however:
I think it's a really really bad practise to do that as you can have various definitions of query string parameters for all sorts of purposes, you should cast to your desired type instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

See the http.IncomingHttpHeaders which holds an index signature on the one hand and named optional properties on the other hand to narrow types for known/specified headers. This works only if | undefined is added in the index signature.

Users could do the same by augmenting ParsedUrlQuery but I agree that this is different and not really an intended usecase.

function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
const globalAgent: Agent;
Copy link
Contributor

Choose a reason for hiding this comment

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

globalAgent is not const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems that way, however changing it on the fly could break references.
I will change it to let.


// Same as module.exports
declare var exports: any;
declare var SlowBuffer: {
declare const exports: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this really const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually exports is passed in by the nodejs module wrapper as an argument.
It is debatable if this is const but assigning it effectively breaks exports as you are changing the reference, you should always set module.exports

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, right. adding properties to exports is the usecase, not assigning to it.

function request(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
function get(options: RequestOptions | string | URL, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
const globalAgent: Agent;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not const. It may be a valid usecase to modify the global agent in an application.

@Flarna
Copy link
Contributor

Flarna commented Sep 24, 2018

Quite a big changeset so maybe I haven't overlooked something...
Please note that inspector.d.ts is a generated file generated via the scripts in types/node/scripts/generate-inspector therefore I think these scripts should be adapted instead of inspector.d.ts.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Merge:Express and removed Awaiting reviewer feedback labels Sep 24, 2018
@typescript-bot
Copy link
Contributor

A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped!

@SimonSchick
Copy link
Contributor Author

SimonSchick commented Sep 24, 2018

@Flarna I am aware it's generated but the link to the generator is dead so I dunno where it is 😛

Copy link
Contributor

@islishude islishude left a comment

Choose a reason for hiding this comment

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

Remove so much export,I don't think that's the right thing to do. there may be compatibility problems.

@typescript-bot typescript-bot removed the Owner Approved A listed owner of this package signed off on the pull request. label Sep 25, 2018
@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Merge:Express labels Sep 25, 2018
@typescript-bot
Copy link
Contributor

@SimonSchick One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you!

@SimonSchick
Copy link
Contributor Author

@islishude The linter made it clear these export keywords were redundant, (except for http2).

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Merge:Express labels Sep 25, 2018
@Flarna
Copy link
Contributor

Flarna commented Sep 25, 2018

@SimonSchick Isn't the generator in the subfolder types/node/scripts/generate-inspector?
I never touched the inspector types so don't know. @kjin I think you did the last update of inspector types. Could you please help regarding the generator?

@SimonSchick
Copy link
Contributor Author

@Flarna my bad, I had scripts hidden in my vscode, some config leak I suppose 😛

@SimonSchick
Copy link
Contributor Author

Update:
Updated generator to produce lint conform code (omit redundant namespacing, wrap doc lines, wrap long method lines).

@SimonSchick
Copy link
Contributor Author

Hey @basarat I think this is ready.

export function parse<T extends {}>(str: string, sep?: string, eq?: string, options?: ParseOptions): T;
export function escape(str: string): string;
export function unescape(str: string): string;
function stringify(obj?: {}, sep?: string, eq?: string, options?: StringifyOptions): string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the first argument is mandatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgive the ghetto windows shell:

C:\Users\Simon>node -v
v10.10.0

C:\Users\Simon>node
> querystring.stringify(undefined)
''
> querystring.stringify()
''
>

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, behavior of node and doc differs here.

@amcasey
Copy link
Contributor

amcasey commented Sep 25, 2018

@Flarna I think you're still reviewing - please let me know if/when you're satisfied.

Copy link
Contributor

@ThomasdenH ThomasdenH left a comment

Choose a reason for hiding this comment

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

The only comment I have is the usage of <any> casting instead of using as any. This is the recommended syntax.

// exports should work same as module.exports
exports = (grunt: IGrunt) => {
// assigning exports is an error in node, hence the cast
(<any>global).exports = (grunt: IGrunt) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the as syntax recommended now?

let x: NodeModule;
let y: NodeModule;
const x: NodeModule = <any> {};
const y: NodeModule = <any> {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose, not a big change, but this should really be added to the lint config if it's so important @basarat

{
let http2Stream: http2.Http2Stream;
let duplex: stream.Duplex = http2Stream;
const http2Stream: http2.Http2Stream = <any> {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting without as.


// ClientHttp2Stream
let clientHttp2Stream: http2.ClientHttp2Stream;
const clientHttp2Stream: http2.ClientHttp2Stream = <any> {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting without as.

let serverHttp2Stream: http2.ServerHttp2Stream;
let headers: http2.OutgoingHttpHeaders;
const serverHttp2Stream: http2.ServerHttp2Stream = <any> {};
const headers: http2.OutgoingHttpHeaders = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting without as.

const onConnectHandler = (session: http2.Http2Session, socket: net.Socket) => {};

let serverHttp2Session: http2.ServerHttp2Session;
const serverHttp2Session: http2.ServerHttp2Session = <any> {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting without as.

/** Github sends auth code so that access_token can be obtained */
/** To obtain and parse code='...' from code?code='...' */
const qsObj = qs.parse<{[key: string]: string}>(p[1].split('?')[1]);
const qsObj = <{ code: string }> qs.parse(p[1].split('?')[1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting without as.

@ThomasdenH
Copy link
Contributor

Not sure if you saw, but there are still these instances of casting with <>;

  • types/grunt/grunt-tests.ts:17
  • types/oauth/oauth-tests.ts:47

@SimonSchick
Copy link
Contributor Author

@ThomasdenH I appreciate the thoroughness but I don't think we should be this nit-picky about this.
I will gladly follow everything that is standartized in the lint config, maybe you should request a change to be made there.

@ThomasdenH
Copy link
Contributor

You're probably right. Still, since the PR is about style anyway I think it's a good idea. Anyway, looks good to me now!

@amcasey amcasey merged commit dfe659d into DefinitelyTyped:master Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Owner Approved A listed owner of this package signed off on the pull request. Popular package This PR affects a popular package (as counted by NPM download counts). Revision needed This PR needs code changes before it can be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants