-
Notifications
You must be signed in to change notification settings - Fork 2
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/typescript #2
Conversation
d2e1073
to
2af4b40
Compare
lib/index.ts
Outdated
return hook !== undefined; | ||
}) as [Hook, Hook][][]; | ||
const edges = [...edges_after, ...edges_before].flat(0); | ||
return toposort.array(mergedHooks, edges).map((hook) => { |
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.
@wdavidw maybe you could help with this part ? I can't get the edges
type right.
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.
I totally suck in Typescript, I had a look at it but no 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.
I understand that it can be intimidating if your not used to the syntax, but what I'm asking is actually quite "simple" and doesn't require to fully understand typescript. You can approach it as any pseudo type language (like the one you wrote in the readme for the parameters types).
You can also pull the PR locally to get some hints from your editor and eslint.
In fact I'm not sure if there is an issue with the typings, if I understood your code correctly, or if there is a bug in the original code.
Could you at least check lines L338 and L342 and tell me if as [Hook, Hook][];
and as [Hook, Hook][][];
are supposed to be the correct return types of the map+filter sequences ?
TS is complaining of receiving in the edges
parameter (L369) a [Hook, Hook][][]
type while it expects a [Hook, Hook | undefined][]
one. What makes me think of an implementation issue is the additionnal []
array dimension that we have here.
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.
I did pull the changes and I confirm that I saw the TS error both in the CLI and in VSCode complaining about the [Hook, Hook][][]
and [Hook, Hook | undefined][]
. However, I didn't know how to read those 2 last hints. I can give it another try
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.
The as
keyword in as [Hook, Hook][]
for example, is a type cast, to indicate to TS what the hook.before.map(...).filter(...)
return type is supposed to be. Here I use it after the filter
because typescript is not able to infer that the resulting array doesn't contain any undefined
values anymore. If you hover the filter
keyword, you'll see what is the actual type TS is inferring ((Hook[] | undefined)[]
in this case).
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.
On L367 we end up with a [Hook, Hook][][]
, which is correct in regards to the current implementation (please confirm), but we need a [Hook, Hook][]
, as toposort.array
expects. We should have one nesting level less.
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.
I found a few things, tests are not passing but I got it to compile
- error.ts, line 2: remove
private
, error code is public - index.ts, line 368: depth
0
inarray_flatten
convert to depth1
inflat
:const edges = [...edges_after, ...edges_before].flat(1);
- index.ts, line 369: pass the
Hook
trait and returnhook
from mapreturn toposort.array<Hook>(mergedHooks, edges).map((hook) => { if (hook) { if ('require' in hook) delete hook.require; if ('plugin' in hook) delete hook.plugin; } return hook });
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, I will have a look
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.
- index.ts, line 369: pass the
Hook
trait and returnhook
from mapreturn toposort.array<Hook>(mergedHooks, edges).map((hook) => { if (hook) { if ('require' in hook) delete hook.require; if ('plugin' in hook) delete hook.plugin; } return hook });
This is not required, typescript infers the Hook
type from arguments.
David, you should be able to fix and adapt the tests now. There is still some work at the typing level (some |
2f32308
to
83ddc5f
Compare
I'd like to hear your opinion about 2 things:
|
There are 2 things I'd like to bring your attention to, in the last (and supposedly final) changes.
I couldn't run the tests but I imported the types in a library I'm developing. Everything works well so far. |
That's fine. My preference is no semicolons for personal projects, not settled for open source projects (csv packages are with semicolons), and single-quotes everywhere (coffeescript heritage).
I am hesitant about this, if a CI does it automatically, new extra commits will pollute the commit history.
I am not too familiar with ts generic but it seems like the way to go for dynamic/user types. Could you give me write access to your fork, this way I could add the tests directly in this working branch. I hope to have some time end of the week. |
There wouldn't be more commit pollution than there currently is. My suggestion is to totally remove the
You should already have write access. |
Hi @LucasDemea, could you please do a review of my commit 41cdf63 I am not too happy of my TS skills, here are a few notes:
|
I will have a look. Not sure I'll find the time this week though |
41cdf63
to
c4278ba
Compare
Hi @wdavidw, did you see my latest comments ? |
@LucasDemea I don't see any new comment. To me, the last comment is "I will have a look. Not sure I'll find the time this week though". Am I missing something ? |
lib/index.ts
Outdated
export type HookHandler<T extends object> = ( | ||
args: T, | ||
handler?: HookHandler<T> | ||
) => null | void | HookHandler<T> | Promise<HookHandler<T>>; |
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.
We should first agree on the HookHandler type because it has implications on many other parts. Does it look good to you ? Or should we broaden the return type to something more permissive ?
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.
args
is currently of type T extends object
. But in your call_sync test, you pass an array. Maybe we should also broaden its type ?
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.
@wdavidw Let me know if you need some explanations about the typings
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.
@LucasDemea I don't see any new comment. To me, the last comment is "I will have a look. Not sure I'll find the time this week though". Am I missing something ?
My bad, my review was left pending ... 🤦
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.
Hi @LucasDemea. args
could be anything. The return value of the handler may also be anything. Honestly, TS always get me confused.
This looks promising! Seems to be before merging the PR I could publish the |
Please propose a definition file. There is still a lot of work pending to complete this PR and no time to do it. |
660a602
to
e45bb0c
Compare
Hi David, I finally found some time to work on the PR again. what I did:
There are still some linting issues left, but I wasn't sure if I could fix them without modify your initial code logic. I'd prefer if you could have a look at these. Tests need to be migrated to TS because coffeescript can't read typescript from what I understand. |
Hi Lucas, I have been thinking a lot about your PR in the last month. My main concern is how will I be able to manage the code base if I am barely able to write a unit test with it. It all come down to the decision to go full TS for which I am fully liable. I know you invested a lot of effort in the PR but would you agree to work on the definition file, instead of migrating |
I see 3 possibilities here :
The tests could be written in almost pure JS if we disable TS compiler type checking features. These features could be enabled later. That could help with migrating progressively to TS. Of course the most beneficial option overall would be the third, especially now that the hard work is done, but I assume you don't have the will or time to learn typescript, and I respect that. On the other hand, I don't see myself throwing away all these code improvements and go back to a far from perfect solution (the second one). Actually this is what I was doing the past week, before jumping back to migrating the code base to full typescript : by integrating your library in one of my project and using the definition file extracted from the first version of my fork, some types issues appeared. I had to fix them directly in the definition file. This was a lot more complicated and imprecise than writing full TS code, and that brought me to the idea of completing the full rewrite once and for all, which is obviously more optimal. I'm left with the first option. I would have to migrate the tests from coffee script to typescript. That shouldn't be to difficult as I saw some existing tools to do this automatically. What are your thoughts about this ? If you decide to try to understand the TS code I could take a couple of hours to explain the code to you via a call and liveshare (I saw you're based in Paris, so you must be speaking french. I'm french too). |
I am proposing a combination of number 2 and 3. We could start collaborating in writing the tests in TS against a definition file on your branch. Once all the tests pass, I will be happy to give you contributor privileges on the repo. From there, we could discuss whether a full TS implementation make sense. You are correct, I am based in Paris and speak french. |
Ok, I will try to fix the call_sync.ts test file now, so that you will understand how tests can work with typescript. |
Back in the days, I did managed to have at least one or two test passing in call_sync.ts. However, if I remember correctly, the code in |
09b9d04
to
5355c43
Compare
call_sync.ts is now working. 4/5 tests pass, when typechecking is disabled. |
Hi Lucas, I spent the last few days trying on my side to implement plug-and-play motivated by me need to put my hands into TS. There are a few thing I am happy about but so many things for wish I am at best not confident. Could you have a look at the feat/typescript-david branch. |
65f5cf5
to
4f0b0f3
Compare
3c2bce8
to
5941a4d
Compare
@LucasDemea your commit are squashed and merged into master in commit 6a8aae7 |
This PR adds typescript support.
Closes #1