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

Flattened types #10350

Open
sebastianbuechler opened this issue Nov 13, 2024 · 1 comment
Open

Flattened types #10350

sebastianbuechler opened this issue Nov 13, 2024 · 1 comment

Comments

@sebastianbuechler
Copy link
Contributor

Especially for beginners, it can be quite hard to understand the types of react-admin due to its highly reusable type structure.

For example in the DataProvider type definition we have for the getList method:
getList: <RecordType extends RaRecord = any>(resource: ResourceType, params: GetListParams & QueryFunctionContext) => Promise<GetListResult<RecordType>>

However, it would be much more helpful to resolve the types directly. Like GetListParams & QueryFunctionContext could be resolved via some VS Code extension (https://marketplace.visualstudio.com/items?itemName=MylesMurphy.prettify-ts):
Image

However, it's IDE-dependent and beginners probably do not know this.

What about using something like simplify from type-fest so it's directly in the codebase?
https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts

Has this ever been considered?

@fzaninotto
Copy link
Member

Hi, and thanks for your idea.

I agree that our reusable types produce complex IDE hints. I'm +1 for making these hints more user friendly. I'm marking this as an enhancement.

I didn't know about the Symplify type. It may be a good idea, but we must make sure that:

  • it keeps the JSDoc for types
  • it doesn't mess up with unions (see ListControllerResult)

Finally, not all type hints are usable in an IDE. For instance, when you start typing n HTML element, IDEs suggest a list of 250 possible attributes. We don't want to spend time refining that kind of list.

My suggestion: open a PR implementing this type of simplification on a small subset of hooks and components, so that we can judge the result.

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

No branches or pull requests

2 participants