-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add types to style mixins #26369
Add types to style mixins #26369
Conversation
@@ -60,7 +67,10 @@ function useControlledState( currentState, options = defaultOptions ) { | |||
fallback | |||
); | |||
|
|||
const setState = ( nextState ) => { | |||
const setState = ( | |||
/** @type {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.
The template T
isn't in scope here 😕
@@ -29,7 +29,10 @@ function useJumpStep( { | |||
const [ isShiftKey, setIsShiftKey ] = useState( false ); | |||
|
|||
useEffect( () => { | |||
const handleShiftKeyToggle = ( event ) => { | |||
const handleShiftKeyToggle = ( | |||
/** @type {KeyboardEvent} */ |
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 get's passed to window.addEventListener
so we do not use the synthetic version from react
* | ||
* @return {number} The sum of values. | ||
*/ | ||
export function add( ...args ) { | ||
return args.reduce( ( sum, arg ) => sum + getNumber( arg ), 0 ); | ||
return args.map( getNumber ).reduce( ( sum, arg ) => sum + arg, 0 ); |
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 and the change below should be equivalent in runtime but appeases the typechecking (I couldn't figure out how to communicate to TS through JSDoc that reduce
was going to be called as reduce<string|number, number>
. It insisted that the return type of reduce
be string|number
. Mapping the array to number
from string|number
first avoids this. From a performance perspective I think this is negligible (you'd only start to notice if we were adding several thousand numbers, right?)
Size Change: +41 B (0%) Total Size: 1.2 MB
ℹ️ View Unchanged
|
This is exciting ❤️ ! Would love to see what others think. My TS knowledge doesn't extend this far 🙈 - to be specific, typing things purely with TSDoc/JSDoc |
Closing as duplicate of #26078 |
Description
Adds/corrects types to the style mixins.
How has this been tested?
Typecheck run and usages confirmed.
Types of changes
New/updated types.
Checklist:
Blocks #26366