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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typescript typings #17

Merged
merged 6 commits into from
Jul 2, 2020
Merged

Conversation

mksony
Copy link
Contributor

@mksony mksony commented Jul 1, 2020

Closes #15

I added two commits, one with the changes which made the typings work as described in the issue and another one which would add a minimal test and related setup.
Please let me know what you think about the included test, I can easily remove it if it should not be part of the regular tests 馃檪
It was inspired by e.g. https://github.com/fastify/fastify-cors

Copy link
Contributor

@jurca jurca left a comment

Choose a reason for hiding this comment

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

@mksony Thanks a lot for submitting this PR!

There are, however, a few issues I would like you to take a look at.

Also, while I like the tsd tool, the version you used is not compatible with node.js 8, which makes the tests fail (see the Checks tab). Please try to use an older version that would work so that this plugin can maintain its current compatibility level.

}

export = FastifyCsrfPlugin;
declare const fastifyCsrf: fastify.Plugin<
Copy link
Contributor

Choose a reason for hiding this comment

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

The fastify.Plugin type accepts only the Options type parameter, see: https://github.com/fastify/fastify/blob/master/types/plugin.d.ts#L10

This also makes HttpServer, HttpRequest and HttpResponse obsolete, so they can be removed from this file completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought so too at first, but since we currently depend on fastify@2.x we need to look at https://github.com/fastify/fastify/blob/2.x/fastify.d.ts#L26 and there we the typings are less sophisticated unfortunately 馃槓

So should we keep it the way it is for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, my bad! Thanks for pointing this out 馃憤 .

Please keep it the way it is.

key?: string;
value?: (req: fastify.FastifyRequest) => string;
cookie?: fastify.CookieSerializeOptions | boolean;
ignoreMethods?: Array<string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please preserve the code style of the main code. string[] is preferable to to Array<string>, and you should use tabs for indentation instead of 2 spaces (I know, indentation is not completely consistent in the code base. Let's improve that a little bit :)).

Also, please use single quotes instead of double.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed 馃檪 See 2b82425.

package.json Outdated
@@ -5,7 +5,8 @@
"main": "lib/fastifyCsrf.js",
"types": "lib/fastifyCsrf.d.ts",
"scripts": {
"test": "tap test/*.js --cov"
"test": "tap test/*.js --cov && npm run typescript",
"typescript": "tsd"
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, the naming here seems a little misleading and confusing. The script itself seems superfluous since it does not configure tsd using env variables or arguments. Could you change the test script to tap test/*.js --cov && tsd, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep you're right. I changed it to your suggestion. See 19cea1d

@@ -0,0 +1,26 @@
import * as fastify from "fastify";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the code style as specified in comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, see 2b82425

<form method = "post" action="/data">
<input type="text" name"field_name"/>
<input type="hidden" value="${request.csrfToken()}"
name="_csrf /* this token can be sent in request header as well */"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see you have copy-pasted this from README :).

Unfortunately, JS comments (/* */) do not play nicely with HTML, could you, please, remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good, point 馃憤 See 188442c

@mksony
Copy link
Contributor Author

mksony commented Jul 2, 2020

@mksony Thanks a lot for submitting this PR!

You're welcome. I am happy to contribute 馃檪

There are, however, a few issues I would like you to take a look at.

I addressed all the inline comments and for #17 (comment) I would need feedback from you, please.

Also, while I like the tsd tool, the version you used is not compatible with node.js 8, which makes the tests fail (see the Checks tab). Please try to use an older version that would work so that this plugin can maintain its current compatibility level.

Thanks for pointing this out. The people maintaining tsd are aware of the problem and merged a PR which addresses the problem just today. See tsdjs/tsd#73. So either we wait until they publish the patch or we go with 0.11 instead of 0.12. I downgraded for now and the tests pass.

Which option should we go for?

Copy link
Contributor

@jurca jurca left a comment

Choose a reason for hiding this comment

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

Thanks a lot for addressing all the issues!

I think it is safe to downgrade tsd for now, since it does not limit our use of it at the moment, is introduced in this PR and it is only a dev dependency.

There is also the option of dropping Node 8 support, but that ought to be up to the project owner when they feel like it, and preferably in a separate PR.

@Tarang11 I am approving this PR 馃殌 , IMO it looks good. Please do a final review if you feel like it and merge it when convenient.

}

export = FastifyCsrfPlugin;
declare const fastifyCsrf: fastify.Plugin<
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, my bad! Thanks for pointing this out 馃憤 .

Please keep it the way it is.

@Tarang11 Tarang11 merged commit cd91f80 into fastify:master Jul 2, 2020
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.

Typescript definitions not working
3 participants