-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Add typescript definitions for built-in middlewares #117
Conversation
Codecov Report
@@ Coverage Diff @@
## master #117 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 17 17
Lines 347 347
Branches 71 71
=====================================
Hits 347 347 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is brilliant, thanks @Juanelorganelo!
Just one question before moving this on:
- Shouldn't we change this line in the
package.json
as well: https://github.com/middyjs/middy/blob/master/package.json#L13
Also, can we move the file in the typescript folder?
@lmammino I tried every possible way I could think of to keep the |
Sorry if this is taking too long, I have been very busy lately and I don't know enough about Typescript. It would be great to have some support by @joseSantacruz on this. I'll try to play with this PR a bit and see if I can figure it out if we can avoid to keep the typescript file in the root folder |
@Juanelorganelo, I did some changes and my editor autocomplete seems to like the definitions now, but I am not sure I am providing types in the right way. Can you double check? Also, it would be great to have some feedback from 2 typescript masters I know like @remojansen and @fsciuti 😇 I look forward to hearing from all of you guys, thanks in advance! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent improvement adding the middlewares typings
typescript/middlewares.d.ts
Outdated
} | ||
|
||
interface ICacheOptions { | ||
calculateCacheId?: (event: any) => Promise<string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is better if you use generics and the latest function type declaration so this interface should be:
interface ICacheOptions {
calculateCacheId?<T>(event: T): Promise<string>;
getValue?<T>(key: string): Promise<T>;
setValue?(key: string): Promise<void>;
}
typescript/middlewares.d.ts
Outdated
} | ||
|
||
interface IWarmupOptions { | ||
isWarmingUp?: (event: any) => boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is better if you use generics and the latest function type declaration so this interface should be:
interface IWarmupOptions {
isWarmingUp?<T>(event: T): boolean;
onWarmup?<T>(event: T): void;
}
typescript/middy.d.ts
Outdated
@@ -38,4 +38,4 @@ declare namespace middy { | |||
} | |||
} | |||
|
|||
export = middy; | |||
export default middy; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not going to works I tested and give me types error if you use import * as middy from 'middy';
, and also remember that the default export is deprecated in favor of module imports. So should stay without default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had problems with this before, not sure if it is the same issues but the following helped me microsoft/TypeScript#5073
Hi @lmammino and @Juanelorganelo I put some comments on the PR, hope this help to improve this new feature |
It looks good but I would recommend adding a few test files under the |
@lmammino Sorry for the delay, I've been really busy at work, anyway I just tested this with the remapped exports and |
Thanks @joseSantacruz and @remojansen! Your support is really really appreciated :) @Juanelorganelo If it gets too tricky to have the typescript definitions inside the |
Thanks all for your valuable contribution on this! |
This pull requests adds typings for the middlewares public API. The file is in the root due to how typescript module resolution works for typings. For more information see this thread
Closes #112