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

NodeGroup Add generic type from incoming data #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

FranzFlueckiger
Copy link

This PR allows typescript users to directly have the type of the incoming data array inferred in all the following functions:
keyAccessor, start, enter, update and leave.
If this PR is accepted, nothing will change from the user's perspective except that they will enjoy code completion where they might expect it to be.

FranzFlueckiger added 2 commits March 27, 2021 22:39
This PR allows typescript users to directly have the type of the incoming data array inferred in all the following functions:
keyAccessor, start, enter, update and leave.
If this PR is accepted, nothing will change from the user's perspective except that they will enjoy code completion where they might expect it to be.
@sghall
Copy link
Owner

sghall commented Jun 13, 2021

Good point 👍 Keep thinking I'm just going to re-write this in TS. I think you need to make it optional, right? So not all TS users need to provide a type?

Like...

type SomeType<T = void> = OtherType<T>;

https://garbagevalue.com/blog/optional-generic-typescript

@FranzFlueckiger
Copy link
Author

Hi Steve, sorry for the late response. You're right that the generic should be optional so that this change is non-breaking for the users.

enter?: (data: T, index: number) => HashMap | Array<HashMap>
update?: (data: T, index: number) => HashMap | Array<HashMap>
leave?: (data: T, index: number) => HashMap | Array<HashMap>
children: (nodes: Array<any>) => React.ReactElement<any>
Copy link

Choose a reason for hiding this comment

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

I feel like it's just as important to tighten-up the any type here too. I've got this type in my codebase:

type ReactMoveNode<Data, State> = {
  key: string;
  data: Data;
  state: State;
};

That I'm using like this:

<NodeGroup
 // ...etc
>
  {(
    nodes: Array<ReactMoveNode<{ id: string }, { top: number; opacity: number }>>
  ) => (
    // ...etc
  )}
</NodeGroup>

It should be possible to wrap all that up together here.

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

3 participants