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

Fix IMiddy and ICorsOptions type definitions #200

Merged
merged 4 commits into from
Jun 7, 2018

Conversation

ossareh
Copy link
Contributor

@ossareh ossareh commented Jun 5, 2018

As per #182 this fixes the types issues on IMiddy and ICorsOptions. before, after, and onError on IMiddy were incorrectly configured:

  • they did not take a function
  • they did not return themselves

While ICorsOptions itself was optional when cors() was being called, the individual properties of it were not.

The project already had the infrastructure to run tests but was missing a few things:

  • @types/node were not present, so typings-tester would fail
  • it was easy to miss this because test:typings was not part of the build workflow; I've now added it to npm test.

I have examples of the tests failing:

These have slightly differing package.json setups which allow them to target the specific tests:

I chose to use the name: foo.types.ts to indicate that the these files are verifying types. Additionally I chose to locate them in __tests__ because that seemed like the most correct place. Finally, I also chose to use the jest notation (and thus include @types/jest) as that allows folks to just copy and paste their tests into foo.types.ts and they'll be picked up by typings-tester.

I believe we have the minimum here to constitute a basis to ask folks to contribute accurate types to the project now. However I decided not to implement tests for all of the types because that would have made the commit much larger. I'm happy to contribute a few types each weekend though :)

 - integrate typings-tester into npm:test
 - write typings-tester tests for middy and cors options
 - minor typescript version bump
 - modernize typescript setup
 - provide @types/jest to allow tests to compile
Copy link
Member

@lmammino lmammino left a comment

Choose a reason for hiding this comment

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

As far as I understand this looks like a great job :) I'd be really happy to merge it but it would be great to have a second opinion by somebody with TypeScript experience:

@peterjcaulfield, @joseSantacruz, @nnyegaard, @fsciuti, @remojansen 🙏

tsconfig.json Outdated
"noEmitHelpers": true,
"noEmitOnError": true,
"noImplicitReturns": true,
"target": "es5",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to change the target from es2015 to es5?

Copy link
Contributor Author

@ossareh ossareh Jun 7, 2018

Choose a reason for hiding this comment

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

oh, good catch. This was not meant to change.

Context: This branch started off as two features, this feature but then also another one which made the tests run on node v8.x - during that development I had an issue where the tests were not running on v6, I changed the value, it didn't make a difference, and I forgot to change it back.

The issue was that I'd switched the entire project over to using ts-jest at some point and it complained about some of the javascript within the project, but only on v6 - so I figured something about targeting or babel was wrong, and I was iterating through that.

I'll go ahead and change it back to es2015.

@nnyegaard
Copy link
Contributor

Expect for the one question everything looks good. This is a good addition!

@lmammino
Copy link
Member

lmammino commented Jun 7, 2018

Thanks for the review @nnyegaard! I'll have this version bumped and merged shortly

@ossareh ossareh mentioned this pull request Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants