Skip to content

Commit

Permalink
useControlledValue: let TypeScript infer the return type (#46164)
Browse files Browse the repository at this point in the history
* useControlledValue: let TypeScript infer the return type

* CHANGELOG
  • Loading branch information
ciampo authored Nov 30, 2022
1 parent 83d54f0 commit 8633ae8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Internal

- `useControlledValue`: let TypeScript infer the return type ([#46164](https://github.com/WordPress/gutenberg/pull/46164))
- `LinkedButton`: remove unnecessary `span` tag ([#46063](https://github.com/WordPress/gutenberg/pull/46063))
- NumberControl: refactor styles/tests/stories to TypeScript, replace fireEvent with user-event ([#45990](https://github.com/WordPress/gutenberg/pull/45990)).
- `useBaseField`: Convert to TypeScript ([#45712](https://github.com/WordPress/gutenberg/pull/45712)).
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/utils/hooks/use-controlled-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function useControlledValue< T >( {
defaultValue,
onChange,
value: valueProp,
}: Props< T > ): [ T | undefined, ( value: T ) => void ] {
}: Props< T > ) {
const hasValue = typeof valueProp !== 'undefined';
const initialValue = hasValue ? valueProp : defaultValue;
const [ state, setState ] = useState( initialValue );
Expand All @@ -40,5 +40,5 @@ export function useControlledValue< T >( {
setValue = setState;
}

return [ value, setValue ];
return [ value, setValue as typeof setState ] as const;
}

0 comments on commit 8633ae8

Please sign in to comment.