-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
react-autosuggest: restrict input props #39186
react-autosuggest: restrict input props #39186
Conversation
@OliverJAsh Thank you for submitting this PR! 🔔 @nicolas-schmitt @pjo256 @robessog @tbayne @cdeutsch @rosskevin @ThomasdenH @ulrichb - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let’s review the numbers, shall we? Comparison details 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. |
This may be a case of your bug is my feature, but this broke our build process, and while I won't argue that it should not have been changed, it maybe should not have just been a patch version change. |
Hm, sorry to hear that @thenovelnomad. Unfortunately, the way |
Ahh, thanks for the details, @andrewbranch. That makes sense. I guess we should lock down our types packages to the patch version. |
@@ -68,7 +68,6 @@ declare namespace Autosuggest { | |||
onChange(event: React.FormEvent<any>, params: ChangeEvent): void; | |||
onBlur?(event: React.FocusEvent<any>, params?: BlurEvent<TSuggestion>): void; | |||
value: string; | |||
[key: string]: any; |
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 is definitely not correct as everything you pass as inputProps
into the component you get as param of renderInputComponent
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.
https://github.com/mui-org/material-ui/blob/master/docs/src/pages/components/autocomplete/IntegrationAutosuggest.js
this throws type errors now...
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.
@dolezel Please can you provide a reduced test case demonstrating the error you're seeing, in a new issue?
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.
I've posted link above. E.g. here https://github.com/mui-org/material-ui/blob/master/docs/src/pages/components/autocomplete/IntegrationAutosuggest.js#L199 it complains that 'classes' does not exist in type 'InputProps'
, but it should be possible to pass anything through and access it (e.g. https://github.com/mui-org/material-ui/blob/master/docs/src/pages/components/autocomplete/IntegrationAutosuggest.js#L50)
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.
I see. In that case, InputProps
should probably be a generic that is shared with renderInputComponent
. Until someone is able to make that change, I would suggest using a cast on the properties which are causing this problem (e.g. classes
):
inputProps={{
// We want to pass these extra props through to `renderInputComponent`. A cast is needed because they are not included in the `InputProps` type.
...{ classes } as InputProps<T>,
id: 'whatever',
// other properties
}}
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.
Ahhh renderInputComponent
, I see.
In this case I would recommend to add the ref
member not to InputProps
but to the RenderInputComponent
callback type (line 123).
Something like (inputProps: InputProps<TSuggestion> & { readonly ref: (instance: HTMLInputElement) => void }) => ...
.
This would avoid adding it to InputProps
thus as input value for the AutoSuggest
component (which would be misleading/wrong because it will get overwritten by AutoSuggest).
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.
Since renderInputComponent
is a thing and you can render components from other libraries in it, I don't think [key: string]: any;
should have been removed.
This broke the code I was using with Ant Design, which supports props like prefix
and suffix
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.
It also broke our implementation with data-
prefixed properties.
It's valid in React so why should it be removed?
Maybe we should extend from a different interface to maintain backward compatibility as this change was "patch" but was breaking change for us.
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.
InputProps
should probably be a generic that is shared withrenderInputComponent
This is the correct fix that doesn't remove type safety. Would someone like to send a PR? I'm happy to review it.
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.
dataset is valid thing in HTML. Yet, we still can't define regex on properties names so we can't type safety date-name
properties.
If we could do that (there is a proposal: microsoft/TypeScript#6579), it would be so easy to implement:
// DOM data attributes later used in HTMLOrSVGElement.dataset
interface DataAttributes {
[key: /data-\w+/]: number | string | boolean;
}
yet as for now, we could do:
// DOM data attributes later used in HTMLOrSVGElement.dataset
interface DataAttributes {
[key: string]: string;
}
But it will break whole type safety on everything 🙈
This brings
InputProps
inline with React's types forinput
. That is, the following errors in React:This also means that
keyof InputProps<T>
returns a union of literals instead ofstring
. This is helpful because it means that keys will be validated in operations such asPick<InputProps<T>, 'autoFocus'>
.Please fill in this template.
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If changing an existing definition:
tslint.json
containing{ "extends": "dtslint/dt.json" }
. If for reason the any rule need to be disabled, disable it for that line using// tslint:disable-next-line [ruleName]
and not for whole package so that the need for disabling can be reviewed.