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

chore!: convert project to typescript #1641

Merged
merged 33 commits into from
Jul 21, 2023
Merged

chore!: convert project to typescript #1641

merged 33 commits into from
Jul 21, 2023

Conversation

robertsLando
Copy link
Member

@robertsLando robertsLando commented Jul 19, 2023

Fixes #1640

Copy link

@sibelius sibelius left a comment

Choose a reason for hiding this comment

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

awesome

@robertsLando robertsLando marked this pull request as ready for review July 20, 2023 14:24
@codecov
Copy link

codecov bot commented Jul 20, 2023

Codecov Report

Patch coverage: 81.43% and project coverage change: -4.32 ⚠️

Comparison is base (d71b000) 85.74% compared to head (9645234) 81.43%.

❗ Current head 9645234 differs from pull request most recent head 0f55a3b. Consider uploading reports for the commit 0f55a3b to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1641      +/-   ##
==========================================
- Coverage   85.74%   81.43%   -4.32%     
==========================================
  Files          13       21       +8     
  Lines        1249     1325      +76     
  Branches        0      316     +316     
==========================================
+ Hits         1071     1079       +8     
+ Misses        178      173       -5     
- Partials        0       73      +73     
Impacted Files Coverage Δ
src/lib/handlers/auth.ts 20.00% <20.00%> (ø)
src/lib/connect/ws.ts 36.80% <36.80%> (ø)
src/lib/is-browser.ts 75.00% <75.00%> (ø)
src/lib/handlers/connack.ts 77.41% <77.41%> (ø)
src/lib/handlers/index.ts 81.57% <81.57%> (ø)
src/lib/connect/index.ts 83.54% <83.54%> (ø)
src/lib/topic-alias-send.ts 83.87% <83.87%> (ø)
src/lib/shared.ts 84.21% <84.21%> (ø)
src/lib/client.ts 86.42% <86.42%> (ø)
src/lib/connect/tls.ts 86.95% <86.95%> (ø)
... and 11 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@robertsLando
Copy link
Member Author

@vishnureddy17 @BertKleewein All tests are working now 🚀

Comment on lines 53 to 56
export default function connect(
brokerUrl: string | IClientOptions,
opts?: IClientOptions,
): MqttClient {
Copy link
Member

Choose a reason for hiding this comment

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

maybe do function overloading here? one signature with just an opts param and another signature with the url string and opts

Copy link
Member Author

Choose a reason for hiding this comment

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

Eveytime I try using function overloading in typescript I give up... I always get the error that says the overloading are not compatible

Copy link
Member Author

Choose a reason for hiding this comment

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

@vishnureddy17 I have been able to add them, check: 1c56921 (#1641)

@vishnureddy17
Copy link
Member

Is it ready for review or are you still working on it? @robertsLando

@robertsLando
Copy link
Member Author

@vishnureddy17 the code is ready for review, I was just testing that npm pack produces a valid package with all exports correctly set.

vishnureddy17
vishnureddy17 previously approved these changes Jul 20, 2023
Copy link
Member

@vishnureddy17 vishnureddy17 left a comment

Choose a reason for hiding this comment

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

I've skimmed through and made some comments. It is a big PR, so I did not go through each line very thoroughly. Let me know if there are particular parts of the PR that you think should be look at more closely.

src/lib/connect/ws.ts Outdated Show resolved Hide resolved
import EventEmitter from 'events'
import { applyMixin } from './shared'

export type EventHandler =
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to have these types? Shouldn't there be typings available for EventEmitter already?

Copy link
Member Author

Choose a reason for hiding this comment

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

A friend of mine (@AlCalzone, a TS wizard 🧙🏼‍♂️ ) suggested me this a while ago. Based on what he told me the TypedEventEmitter is far better because:

you get autocomplete for the events that exist, and you get syntax help for the callback parameters, and typescript will yell at you if you accidentally use an event wrong. No more typos in event names or non-existent events, no more wrong callback params, no more looking up elsewhere what callback params there are

Copy link
Contributor

Choose a reason for hiding this comment

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

Examples for a class that is such a TypedEventEmitter:
grafik
grafik
grafik

Copy link
Member

Choose a reason for hiding this comment

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

Ah, neat!

@robertsLando
Copy link
Member Author

robertsLando commented Jul 21, 2023

@vishnureddy17 @BertKleewein I'm done here, I will check the code another time to see if I spot something but I would merge this if you agree. If you want to take some time to review this just let me know and I will wait till next week before merging

@vishnureddy17
Copy link
Member

If you think it's good to merge, go for it

@robertsLando robertsLando merged commit df7881f into main Jul 21, 2023
7 checks passed
@robertsLando robertsLando deleted the ts-rewrite branch July 21, 2023 13:55
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

Successfully merging this pull request may close these issues.

FEATURE - Convert to Typescript
4 participants