-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
components: InputControl to TypeScript #33696
components: InputControl to TypeScript #33696
Conversation
Size Change: +1.93 kB (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
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.
Great work, @sarayourfriend !
It's a bit hard for me to review in detail all of the types that you extracted to the types.ts
file, since this is quite a big PR and I'm not super familiar with how the component works internally.
I tried to focus particularly for any potential runtime change, and left a few comments
return { | ||
...initialInputControlState, | ||
...initialState, | ||
initialValue: value, | ||
}; | ||
} as InputState; |
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.
Why does this need to be explicitly cast? TypeScript should be able to infer and combine the types from the other objects. If there's an error or something, there may be a bug there that the cast is hiding?
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 was because the initialValue
couldn't be undefined
and the Partial<InputState>
was making it allowed to be undefined. But I think previously this was allowable anyway so I've made value
and initialValue
undefined.
Though won't that mess up the "controlled-ness" of the input? Should we only allow "empty" values but not undefined?
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'm going to merge this PR and we can refine the types for this if we decide it's a problem. Currently I think we're not introducing anything that isn't already true for the intrinsic input
element.
dispatch( { | ||
type, | ||
payload: { value: nextValue, event }, | ||
} ); | ||
} as actions.InputAction ); |
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.
Same here I guess. What's the error if we don't explicitly cast this object?
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 complains that the type
parameter must be INVALIDATE
for some reason. I'm not sure why it complains here and not in the other places 🤔
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 great, Sara! Thanks for working on this!
* Convert Select to TypeScript * Stop spreading props into InputBase and add all HTML attributes for select * Remove need for `omit`
Whoops, I accidentally merged the SelectControl into this PR 😬 But it's been reviewed here #33784 |
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.
LGTM 🚀
@diegohaz could you also have a final look at this PR? There's only a couple of open conversations left
Description
I did this refactor while I was working on something else so I figured I might as well open a PR for it.
It just converts the InputControl to TypeScript and (I think) improves the way the reducer code is structured while we're at it.
How has this been tested?
Storybook should work the same for InputControl, NumberControl and UnitControl, the last two depend on InputControl.
TS build should pass as well.
Types of changes
Janitorial
Checklist:
*.native.js
files for terms that need renaming or removal).