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

TypeScript error for /@dnd-kit/utilities #116

Closed
airtable-JayRansijn opened this issue Mar 3, 2021 · 6 comments · Fixed by #154
Closed

TypeScript error for /@dnd-kit/utilities #116

airtable-JayRansijn opened this issue Mar 3, 2021 · 6 comments · Fixed by #154

Comments

@airtable-JayRansijn
Copy link

I am getting the following issue in our TypeScript check:

../../node_modules/@dnd-kit/utilities/dist/types.d.ts(3,59): error TS2344: Type 'number' does not satisfy the constraint 'keyof Arguments<T>'.
  Type '0' is not assignable to type '"forEach" | "length" | "slice" | "push" | "reverse" | "fill" | "map" | "filter" | "toString" | "concat" | "indexOf" | "lastIndexOf" | "includes" | "sort" | "toLocaleString" | "pop" | ... 13 more ... | "values"'.

I will be investigating more, but thought I share here as well.

@clauderic
Copy link
Owner

What version of TypeScript are you using?

@airtable-JayRansijn
Copy link
Author

We are at 4.1.3. I am about to try to patch-package and maybe split up the args in types into a separate type:

export type ModifierArgs = {
  transform: Transform;
  activeNodeRect: ViewRect | null;
  draggingNodeRect: ViewRect | null;
  containerNodeRect: ViewRect | null;
  overlayNodeRect: ViewRect | null;
  scrollableAncestors: Element[];
  scrollableAncestorRects: ViewRect[];
  windowRect: ClientRect | null;
};

export type Modifier = (args: ModifierArgs) => Transform;

This might be a long shot, but one of my co-workers is mentioning there was an issue with Array.isArray with 4.1.2/4.1.3: microsoft/TypeScript#40463 microsoft/TypeScript#41808

Let me know if you have any suggestions.

@airtable-JayRansijn
Copy link
Author

This seems to work for us as well, and is the patch we are likely picking to avoid patching both packages:

type FirstArgument<T> = T extends (firstArg: infer U, ...args: Array<any>) => any ? U : never

@clauderic
Copy link
Owner

I personally can't replicate, though haven't tried on that specific version of TypeScript. Do you want to open a pull request?

@airtable-JayRansijn
Copy link
Author

Afaict, FirstArgument is only used in this one place. One option is to remove it altogether and split up the modifiers args type. Or if you want to keep FirstArgument around for something else I can make the change described above.

@clauderic
Copy link
Owner

Hey @airtable-JayRansijn, I don't think FirstArgument is used anywhere else in the codebase so no strong opinions either way. Do feel free to open a PR if this is blocking you though.

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 a pull request may close this issue.

2 participants