Skip to content

Commit

Permalink
useControlledValue: let TypeScript infer the return type (WordPress#4…
Browse files Browse the repository at this point in the history
…6164)

* useControlledValue: let TypeScript infer the return type

* CHANGELOG
  • Loading branch information
ciampo authored and mpkelly committed Dec 7, 2022
1 parent f76c2dd commit 020c67b
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 020c67b

Please sign in to comment.