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

Add Typescript definitions #350

Closed
nlochschmidt opened this issue Apr 30, 2020 · 11 comments
Closed

Add Typescript definitions #350

nlochschmidt opened this issue Apr 30, 2020 · 11 comments

Comments

@nlochschmidt
Copy link

While trying to integrate promster with our service written in TypeScript I noticed that there don't seem to be typings for @promster/express. So needless to say, I'd love to see Typescript support for this.

@tdeekens
Copy link
Owner

I‘d love to see them too. Ideally we would rewrite the library to TS to avoid outdated types if forgotten to be updated.

Do you have any intention or see an ability of opening a PR for this yourself?

@nlochschmidt
Copy link
Author

If the API doesn't change often, then a rewrite only to keep TS definitions in sync, is probably not the best use of anyone's time 😅, right?

@tdeekens
Copy link
Owner

tdeekens commented May 1, 2020

In a way no. In another it's quite risky. I've had experience with thinking exactly that in the past in libraries. Then outdated types are frustrating.

@nlochschmidt
Copy link
Author

TypeScript 3.7+ supports generating type definitions from JSDocs. I could try that out and open a PR if it works well.

Would that be useful?

@tdeekens
Copy link
Owner

tdeekens commented May 1, 2020

That sounds like a good compromise. Thanks!

@nlochschmidt
Copy link
Author

I did a proof of concept for generating the declarations based on https://voxpelli.com/2019/10/use-type-script-3-7-to-generate/

The result is in this branch: nlochschmidt/promster@master...nlochschmidt:typescript-definitions

To generate the type declarations (and run the typechecker) you need to run yarn build:declarations.

The declarations look a bit ugly though. TS creates a lot of *.d.ts files and merging them using the outFile option sadly doesn't let Typescript import the generated definitions from one module (metrics) to another (express) for some reason.

@nlochschmidt
Copy link
Author

Funny enough there seems to be a problem with the defaultedOptions here:

createRequestRecorder.defaultedOptions,

could it be that those should be defaultOptions according to:
createRequestRecorder.defaultOptions = defaultOptions;

@tdeekens
Copy link
Owner

tdeekens commented May 2, 2020

Funny enough there seems to be a problem with the defaultedOptions here:

This to me also looks wrong. Odd that it never surfaced as a bug. Will have a look and fix independently quickly if needed. Thanks.

TS creates a lot of *.d.ts

You mean one d.ts file per module we add comments to? That is relatively normal. Only if we'd write one large type definition across modules we'd have it in one file. If we look at the types of flopflip here (another library of mine) which is fully written in TypeScript, we can see that we also got a symetry between the modules written in TypeScript and the d.ts files.

@tdeekens
Copy link
Owner

tdeekens commented May 2, 2020

I released a fix for the mentioned option defaulting across packages

Successfully published:
 - @promster/[email protected]
 - @promster/[email protected]
 - @promster/[email protected]
 - @promster/[email protected]
 - @promster/[email protected]
 - @promster/[email protected]

@tdeekens
Copy link
Owner

tdeekens commented May 2, 2020

Here is a PR rewriting the library entirely to TypeScript. Little Saturday lockdown activity 😄. Not 100% perfect yet but pretty good as a start I think. THe hapi plugin is notoriously hard to type as it mitigates a breaking hapi version.

@tdeekens tdeekens closed this as completed May 3, 2020
@nlochschmidt
Copy link
Author

Thanks a lot for your work 👍

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

No branches or pull requests

2 participants