Skip to content

Commit

Permalink
compose: Type withState as any (#32326)
Browse files Browse the repository at this point in the history
* compose: Try typing `withState` in a naïve way

* compose: Type withState as any

* Move withState back to regular JavaScript

* Fix file formatting

* Put back initialState default value
  • Loading branch information
sarayourfriend authored Jun 14, 2021
1 parent dd21364 commit cf778e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,11 @@ via props.

_Parameters_

- _initialState_ `?Object`: Optional initial state of the component.
- _initialState_ `any`: Optional initial state of the component.

_Returns_

- `WPComponent`: Wrapped component.
- `any`: A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.


<!-- END TOKEN(Autogenerated API docs) -->
Expand Down
8 changes: 4 additions & 4 deletions packages/compose/src/higher-order/with-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
*
* @deprecated Use `useState` instead.
*
* @param {?Object} initialState Optional initial state of the component.
* @param {any} initialState Optional initial state of the component.
*
* @return {WPComponent} Wrapped component.
* @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.
*/
export default function withState( initialState = {} ) {
deprecated( 'wp.compose.withState', {
Expand All @@ -26,8 +26,8 @@ export default function withState( initialState = {} ) {

return createHigherOrderComponent( ( OriginalComponent ) => {
return class WrappedComponent extends Component {
constructor() {
super( ...arguments );
constructor( /** @type {any} */ props ) {
super( props );

this.setState = this.setState.bind( this );

Expand Down
1 change: 1 addition & 0 deletions packages/compose/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"src/higher-order/pure/**/*",
"src/higher-order/with-instance-id/**/*",
"src/higher-order/with-global-events/**/*",
"src/higher-order/with-state/**/*",
"src/hooks/use-async-list/**/*",
"src/hooks/use-constrained-tabbing/**/*",
"src/hooks/use-copy-on-click/**/*",
Expand Down

0 comments on commit cf778e6

Please sign in to comment.