-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
feat: Add Typescript definitions #184
Conversation
Whoa! @theogravity this is great, I will go through the PR to make sure nothing was missed soon. |
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.
@theogravity i did a first pass review and identified a number of things that need fixing, in addition to those we neeed to add generators and the customization functionality, some of this is already part of the community maintained DefinitelyTyped.
I appreciate the effort you've put into this.
lib/index.d.ts
Outdated
/** | ||
* Returns the <Client> class tied to this issuer. | ||
*/ | ||
Client: { new (metadata: IClientMetadata, jwks?: object) } |
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.
dtto as jwks
above.
@ulrichb @YangusKhan @RMHonor as the three contributors to the DefinitelyTyped types, i would appreciate your review here, as well as believe its in your best interest since it would replace the types you've been maintaining. |
lib/index.d.ts
Outdated
*/ | ||
deviceAuthorization(parameters?: IDeviceAuthParameters, extras?: IDeviceAuthExtras): Promise<IDeviceFlowHandle> | ||
|
||
[key: string]: any |
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.
Are you sure we want this extension here? We shouldn't be assuming there are additional properties on a client
lib/index.d.ts
Outdated
*/ | ||
keystore (forceReload?: boolean): Promise<JWKS.KeyStore> | ||
|
||
[key: string]: any |
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.
As above, should an Issuer
allow additional types like this?
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.
My linter fails if it's not included since it's implemented in IIssuer
Can we also have |
I'd like someone to write .ts test file using the types so that we may have a CI job verifying them. Any takers? |
@panva I will take it (via |
Great! While it's better to have definitions instead of not to have definitions at all... wouldn't it better to convert the project to typescript? What do you think @panva ? Maybe step by step.
I'm not sure that this would help to check definitions. AFAIK you will check fictional[1] definitions with fictional[2] tests. [1] fictional, because they can be not related to concrete implementation. Maybe it's better to convert all tests to ts as a first step? |
Let's park the tests for now until we're satisfied with the state of the definition. @Bessonov exposing types is as far as I'm willing to go at this point in time. |
Thank you everyone for the quick turnaround! I've addressed the most recent comments - apply |
@theogravity thank! Re-iterating on the rest of missing pieces
And also the I appreciate the effort you've put into this. |
Thank you all for feedback and contributions. This has landed in 3.7.0 |
If the consuming project doesn't have
=> Should we move |
I intentionally did not do that, I don't see why non-ts users should have this as a dependency. Maybe add a typescript readme section with this detail? Is that a big deal? Aren't ts users used to installing types? I assumed they are. |
My first instinct was to put it in peer dependencies, as it then at least notifies the user. But perhaps optional dependencies would be more appropriate? Although it's not an approach I've encountered before |
@RMHonor neither of these two applies optionalDependencies
peerDependencies
|
@panva The (small) problem exists if you want to use Optional dependency looks like a good option :). |
It isn't, it still installs for everyone. It just that it can optionally fail to install. |
How is it unnecessary? If you're using TS you need those types. If you don't you don't have to install it. |
Something like |
If you don't use => "error TS7016: Could not find a declaration file for module 'got'" |
In that case, i'm keen to remove the type dependency altogether and make it
and jsdoc add |
Why is a normal dependency so bad? Packages often pull dependencies which aren't used in all cases / for all users. An example: |
Another argument: Also other packages to it that way. For example |
Packages often do, I choose not to. @types/got has three dependencies which also pack other transitive dependencies. Showcasing bloated packages that do this is not an argument if i'm honest. I was about to add the dependency then i checked what it means in terms of other transitive dependencies, so instead I'll move forward with the removal of that import altogether replacing it with the actual object with properties that make sense. |
v3.7.1 fixes this. |
👍 |
Just tested it. Compiles fine without Many thanks @panva! |
Thank you everyone! |
Thanks a lot @theogravity, really appreciate these definitions |
I've handcrafted TS defs that is based on the API documentation and analysis of the project files.
We have had no problems using it in a project we're working on so far.
I'm unsure if you've worked with Typescript or not, but I've done my best to make sure that for return types where a class is involved, that an interface is returned instead.
This allows for the creation of a mocked class when writing unit tests, vs doing class definition overrides.
An exception case would be
TokenSet
as it doesn't do anything complicated and is pretty much a plain object under the hood.