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

Refactor module in TypeScript #60

Merged
merged 19 commits into from
Apr 17, 2019
Merged

Conversation

ltetzlaff
Copy link
Contributor

Hi there, I figured I use this module quite a bit and at some point wasn't sure whether its internals were working correctly (spoiler: they did) so I added some types to make debugging easier and thought it might be worth giving a little more attention.

I used the nice and verbose jsdoc summaries by @BendingBender and realised on the way I can also resolve this discussion #57 (review) by using basically just one line here extends EventEmitter<'active'> 👋

@sindresorhus
Copy link
Owner

Yeah, makes sense for such a complex module. Thanks for doing it :)

I don't use TSLint anymore, since it's being deprecated. Can you replace it with XO? See: sindresorhus/is@ea4204f

package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
source/index.ts Outdated
interval: 0,
concurrency: Infinity,
autoStart: true,
// @ts-ignore This default is a little nasty!
Copy link
Owner

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the classic old typescript problem of passing in class constructors from generics without being able to pass in types because they don't really exist 🤷‍♂️
Screenshot 2019-04-11 at 02 13 15
Screenshot 2019-04-11 at 02 13 23

Copy link
Owner

Choose a reason for hiding this comment

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

@BendingBender Any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix for now: #60 (comment)

source/index.ts Outdated Show resolved Hide resolved
source/lower-bound.ts Outdated Show resolved Hide resolved
source/options.ts Outdated Show resolved Hide resolved
source/priority-queue.ts Outdated Show resolved Hide resolved
source/priority-queue.ts Outdated Show resolved Hide resolved
source/priority-queue.ts Outdated Show resolved Hide resolved
source/queue.ts Outdated Show resolved Hide resolved
@ltetzlaff
Copy link
Contributor Author

Thanks for the review, I think edd0356 is my favorite commit ever 😄

Should be all good now, I had to comment out two linter rules that happened because of bugs in the linter or plugins involved such as import-js/eslint-plugin-import#1304 (just requires a version bump somewhere since it has been merged already) and someone to tell ava that ts files can be valid test files as well :)
Screenshot 2019-04-11 at 02 33 00

package.json Outdated
"call-signature",
"property-declaration",
"member-variable-declaration"
]
Copy link
Owner

Choose a reason for hiding this comment

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

Can you explain these rule changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also due to a rule in the old tslint config, it required

() => {}

to have a defined return type but had the conflicting rule of no redundant typedefs since it could be inferred. Good we dropped that anyways 🔧

tsconfig.json Outdated Show resolved Hide resolved
source/index.ts Outdated

private _resolveIdle: ResolveFunction = empty;

constructor(opt?: Options<QueueType, EnqueueOptionsType>) {
Copy link
Owner

Choose a reason for hiding this comment

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

opt => options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that requires a typecast (or custom typeguard when using a method) to tell ts it can't be undefined anymore thus helping out since it allows us to drop the @ts-ignore 🎉

@sindresorhus sindresorhus merged commit a9d3ad9 into sindresorhus:master Apr 17, 2019
@sindresorhus
Copy link
Owner

Looks good. Thanks for doing this, @ltetzlaff :)

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.

None yet

2 participants