-
Notifications
You must be signed in to change notification settings - Fork 155
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 #207
Conversation
Just curious - what's the reasoning for not adding these types to the By checking these type definitions into this project, |
Hi @mmmeff, I am certainly happy to create DefinitelyTyped PR's for the aws-xray-sdk packages instead if that's the better option. But if the maintainers are open to it, I think having the type definitions right next to the source makes it easier to check: "do these types align with the implementation?" Potentially they could be updated along with JS changes to the public API, even in the same PR, without requiring a separate PR and review process in DefinitelyTyped. Then a TypeScript user can simply install this package and (hopefully) trust that the types that come along with it are in sync with the source. For what it's worth, aws-sdk had a @types/aws-sdk package until version 2.7.0, and since then has been including types with aws-sdk itself -- though it is able to automatically generate some of them (maybe there's even something along those lines that could be built here too?) |
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.
To answer your questions:
Moving forward, we will be supporting TypeScript definitions in future releases of the SDK. The only foreseeable issue is that when we separate the AWS SDK dependency from the core module (item 4 in #157) we'll have to remove all TS definitions imported from As a final note, I am new to TypeScript (as you could tell by my reliance on @ArturGrigio to review this). I'd appreciate if the community point out any misses on my end as I make changes to TS definitions during future maintenance. |
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.
Thank you both @willarmiros and @ArturGrigio for reviewing - I've just merged the latest in from 2.x and added that segment.setUser()
operation to segment.d.ts, and also updated the setServiceData
type following our discussion.
As far as that first question I had, the types I was wondering about were mainly the properties on the sub/segment classes - whether they were public or private. So if things seem fine as they are now, that sounds good to me!
import * as AWS from 'aws-sdk'; | ||
|
||
declare class Aws { | ||
constructor(res: AWS.Response<any, any>, serviceName: 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.
Here's the first of two references to aws-sdk
- it could become res: any
, no problem.
(callback?: Callback<D>): AWS.Request<D, AWS.AWSError>; | ||
} | ||
|
||
export type PatchedAWSRequestMethod<P, D> = AWSRequestMethod<P & { XRaySegment?: Segment | Subsegment }, D>; |
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 aws_p.d.ts
file has the only other reference to aws-sdk
- it patches the AWS.Service
classes in the return value of captureAWS
and captureAWSClient
so their request methods take an additional XRaySegment
parameter.
After the dependency on aws-sdk
is removed, I think in the worst case these functions could be generic identities that take any type T
and return it.
Potentially, the referenced AWS type definitions (AWSError
, Request
, Service
) could even be copied into this package and I think the types could stay about as they are now, thanks to TypeScript's structural type system, though maybe questionable whether that'd be worth it / a good idea...
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.
Copying the definitions over is a possibility, I will get in touch with the AWS SDK team to see what they recommend.
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.
Review has been completed, merging!
May i know when this will release to npm? |
It will be included in the 2.5.0 release of the SDK. I cannot give an exact date but I will update this when it is released. |
@kwongkz v2.5.0 has been released to NPM. |
Awesome, thanks @willarmiros! I was just looking again, should the |
I guess that was missed on our end as well. Hmm this is where my TS knowledge is lacking. It is always invoked with an argument in the segment slot, but when operating in automatic mode, Regardless, it should definitely allow for |
As it is now, my understanding is that
will be accepted if If the type is Would you accept 2.x patches for this sort of thing? If so I'm happy to open a PR. |
That makes sense. I agree that we want your proposal, and I'd accept a PR but our release process is quite cumbersome so it might only end up getting released as 3.0. If it's clearly a large pain for customers, I'll also release it as 2.5.1. |
Sounds good, thanks -- yeah this change doesn't feel like it warrants a new release by itself. I'll open a PR! |
(moved from the issue, as this seems like a better place. If you want me to open a proper issue, I will. But I think it's just a question for now) @willarmiros @esilkensen Is it on purpose that @types/continuation-local-storage has been added to dependencies instead of dev-dependencies? That seems like a mistake, as it'll make the package larger (right now, that of course drowns in comparison to the aws-sdk, but when that is removed, the typings is the largest dependency by far) |
Hey @LosD, since the I think it's most convenient as a Anyway, it looks like the |
@esilkensen Hmmm, you may be right, I mainly do application development, so maybe library development HAS to do it this way, and rely on tree-shaking not to bring it to runtime (something we currently can't do in our project, because annoying reasons 🤦♂️). However, while the size of edit: from "@types/continuation-local-storage": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/@types/continuation-local-storage/-/continuation-local-storage-3.2.2.tgz",
"integrity": "sha512-aItm+aYPJ4rT1cHmAxO+OdWjSviQ9iB5UKb5f0Uvgln0N4hS2mcDodHtPiqicYBXViUYhqyBjhA5uyOcT+S34Q==",
"requires": {
"@types/node": "*"
}
} |
Just read TypeScript's Publishing document, and they recommend doing it exactly as you are doing it, so it's just me missing finer points in library publishing. 😊 I'll try to find out why it ends up in my runtime dependencies (other unused modules doesn't seem to) |
Ah, thanks, good call -- yes, and Well, I'm interested what others think about this, too... Since this package is only referencing that single |
Or going back to your initial point about not needing the types at runtime, maybe it gets to (like others mentioned up above) whether we do want the types packaged with this library or if they're better off as a separate |
For me, I kinda like that it's integrated; It shows that the project takes responsibility (though in some cases, that's a promise that's not kept), but if it packing developer-only stuff into users' runtimes, that might be a good reason to avoid it. But then again, it is probably me that needs to get the project packaging fixed. |
Issue #, if available: #14
Description of changes:
This PR makes a complete first pass at adding TypeScript definitions for aws-xray-sdk. It leverages some of the work done in a previous PR that seems to be abandoned (#109, thank you to that author!)
I realize it's a pretty big PR, so I will be happy to do anything I can that might make it easier to review, and of course to iterate on it in response to any feedback.
It adds .d.ts files next to the corresponding .js files, and a
"types": "lib/index.d.ts"
entry to each package.json.For testing, it uses the
tsd
tool which by default looks for TypeScript files to check in atest-d
directory; each package has atest-d/index.test-d.ts
file which exercises its TypeScript definitions, and thetest
script has been updated to runtsd
as well.Some initial questions I have:
@types
packages for express/mysql/postgres?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.