-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 records paths inferred from type compatible with react-hook-form #10279
Conversation
packages/ra-core/src/types.ts
Outdated
@@ -13,9 +14,11 @@ export interface RaRecord<IdentifierType extends Identifier = Identifier> | |||
id: IdentifierType; | |||
} | |||
|
|||
export type SortOrder = 'ASC' | 'DESC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is already defined in ra-ui-materialui (packages/ra-ui-materialui/src/field/types.ts), I'm afraid of a conflic. As this change seems to be unrelated to the subject of the PR, could you revert it?
// Useful for props such as "source" in react-admin components | ||
export type ExtractRecordPaths<T extends RecordValues> = | ||
// Trick that allows to check whether T was provided | ||
[T] extends [never] ? string : RecordPath<T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we used AnyString
as the default value, now it's string
. Isn't it a BC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, AnyString
is no longer necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More precisely, AnyString
wasn't needed before. It was unnecessary already. It's only useful for HintedString
typecheck fails |
Problem
Fixes #9849
Records paths inferred from type using
hotscript
aren't compatible with those inferred byreact-hook-form
Solution
Declare our own types for path inference that currently just re-export those from
react-hook-form
, making us more resilient to future changes.How To Test
InvoiceShow
of the CRM demo and add a type parameter to theTextField
of the Order reference. TheTextField
source
should be valid and trying to replace it should trigger the IDE autocompletion, showing allOrder
fieldsAdditional Checks
master
for a bugfix, ornext
for a feature