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

Make dataProvider types generic #5894

Closed
andrico1234 opened this issue Feb 10, 2021 · 4 comments
Closed

Make dataProvider types generic #5894

andrico1234 opened this issue Feb 10, 2021 · 4 comments

Comments

@andrico1234
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The types for the data provider methods aren't generic, and are often written like the following:

interface UpdateParams {
  id: Identifier;
  data: any;
  previousData: Record;
}

This means that when I create a function like this:

const dataProvider: DataProvider = {
  update: (resource, params) => {
      return updateResource(data);
  },
};

async function updateResource(body: UpdateParams) {
  const { data } = body
  // fetch request
}

The type of body is any, even though it's likely I know what the type is at this point.

Describe the solution you'd like

interface UpdateParams<T = any> {
  id: Identifier;
  data: T;
  previousData: Record;
}

This should be a backward compatible type as the generic defaults to any which is existing behaviour.

If you're happy for this to go in, I'll be happy to make a PR to update all of the dataProvider method types.

@djhi
Copy link
Collaborator

djhi commented Feb 11, 2021

Hi @andrico1234 and thanks for the suggestion! We know we have to improve the types around the dataProvider and any help is welcome! Please open a PR so that we can discuss how we do it and iterate.

@andrico1234
Copy link
Contributor Author

Sounds good! i'll whip up something and get your thoughts

@andrico1234
Copy link
Contributor Author

Super tiny MR here

@fzaninotto
Copy link
Member

Fixed by #5934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants