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

Add generics to ArrayHelpers type #911

Open
nzacca opened this issue Sep 16, 2018 · 4 comments · May be fixed by #3401
Open

Add generics to ArrayHelpers type #911

nzacca opened this issue Sep 16, 2018 · 4 comments · May be fixed by #3401
Labels

Comments

@nzacca
Copy link
Contributor

nzacca commented Sep 16, 2018

Current Behavior

The current ArrayHelpers type does not use generics in its type.

Desired Behavior

It would be nice if the ArrayHelpers added generics so that we could type check the inner methods as well.

Suggested Solution

export type FieldArrayRenderProps<T = any, Values = any> = ArrayHelpers<T> & {
  form: FormikProps<Values>;
  name: string;
};

interface ArrayHelpers<T = any> {
  push: (obj: T) => void;
  handlePush: (obj: T) => () => void;
  swap: (indexA: number, indexB: number) => void;
  handleSwap: (indexA: number, indexB: number) => () => void;
  move: (from: number, to: number) => void;
  handleMove: (from: number, to: number) => () => void;
  insert: (index: number, value: T) => void;
  handleInsert: (index: number, value: T) => () => void;
  replace: (index: number, value: T) => void;
  handleReplace: (index: number, value: T) => () => void;
  unshift: (value: T) => number;
  handleUnshift: (value: T) => () => void;
  handleRemove: (index: number) => () => void;
  handlePop: () => () => void;
  remove(index: number): T | undefined;
  pop(): T | undefined;
}

Who does this impact? Who is this for?

  • No impact if we use defaults for the generics
  • Allows users to strongly type the arrayHelpers prop if desired.

I'm willing to submit a PR for this if this sounds ok.

@stale
Copy link

stale bot commented Nov 15, 2018

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

@stale stale bot added the stale label Nov 15, 2018
@nzacca
Copy link
Contributor Author

nzacca commented Nov 15, 2018

@jaredpalmer just wondering if this is something you'd like me to work on. Happy to do it (or not do it). 😄

@stale stale bot removed the stale label Nov 15, 2018
@stale stale bot added the stale label Jan 14, 2019
@IronSean
Copy link

I also would like this. Currently I'm trying to figure out some type hijinks to force form to have the type of the form to get type checking when I access it within my FieldArray block, or just passing the form prop down from the outer Formik render prop because it's typed. But neither as as ideal as just being able to type the arrayHelpers.

I was coming here to offer to make my own PR about this issue, but found this currently existing. I know you're in the thick of v2 prep but let me or @nzacca know if you'd like a PR for this @jaredpalmer

@stale stale bot removed the stale label May 31, 2019
@stale stale bot added the stale label Jul 30, 2019
@IronSean
Copy link

IronSean commented Nov 1, 2019

Made a PR at #1982

@stale stale bot removed the stale label Nov 1, 2019
@stale stale bot added the stale label Dec 31, 2019
@Philipp91 Philipp91 linked a pull request Nov 7, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants