-
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
Address review comments related to the keyboard shortcuts refactor: #19395
Conversation
473c22d
to
66623aa
Compare
/** | ||
* A block selection object. | ||
* | ||
* @typedef {Object} WPKeyboarShortcutConfig |
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.
Typo:
* @typedef {Object} WPKeyboarShortcutConfig | |
* @typedef {Object} WPKeyboardShortcutConfig |
* @param {Object} options Shortcut options. | ||
* @param {string[]|string} shortcuts Keyboard Shortcuts. | ||
* @param {Function} callback Shortcut callback. | ||
* @param {WPKeyboarShortcutConfig} options Shortcut options. |
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.
* @param {WPKeyboarShortcutConfig} options Shortcut options. | |
* @param {WPKeyboardShortcutConfig} options Shortcut options. |
@@ -19,6 +19,15 @@ import { displayShortcut, shortcutAriaLabel, rawShortcut } from '@wordpress/keyc | |||
*/ | |||
const EMPTY_ARRAY = []; | |||
|
|||
/** | |||
* {{[string]:Function}} Shortcut Formatting Methods. |
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 probably one where, since the keys are known, we could use Object
type combined with @property
tags.
In any case, since this isn't using @type
, it's not doing anything currently anyways.
Finally, it's actually an object two levels deep before getting to the function, since each of the "handlers" (displayShortcut
, etc) are actually objects themselves.
* {{[string]:Function}} Shortcut Formatting Methods. | |
* {{[string]:Function}} Shortcut Formatting Methods. |
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.
we could use
Object
type combined with@property
tags.
In implementing this, I've found that using the {Object}
type in TypeScript has a high likelihood to trigger the any
type fallback unintentionally, even when complemented by @property
tags or types for the keys (see also this syntax vs. Object<M in WPKeycodeModifier,Function>
).
We probably need to work through this a bit more. Not sure if it's a shortcoming of TypeScript, or just an accurate reflection of the "Object" type allowing for more keys than those explicitly defined (e.g. prototype members).
- _representation_ `string`: Type of reprensentation. (display, raw, ariaLabel ) | ||
- _representation_ `null`: Type of representation (display, raw, ariaLabel). |
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.
Related: #18045
* @property {string} character Character. | ||
* @property {string} [modifier] Modifier. | ||
* @property {string} character Character. | ||
* @property {WPKeycodeModifier|undefined} modifier Modifier. |
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 change was a bit unfortunate, I found. The previous [modifier]
optional property syntax should be fine, but for some reason the TypeScript tooling does not pick up on it being an issue unless it was explicitly a union type with undefined
, even though it detects it as optional.
It only (correctly) flags an error when trying to use a modifier method on WPKeycodeHandlerByModifier
when it's typed using the undefined union:
Thanks for the updates Andrew |
Address review comments related to the keyboard shortcuts refactor:
#19320 (comment)
https://github.com/WordPress/gutenberg/pull/19318/files#r362599806