Skip to content

TypeScript: migrate keyboard-shortcuts package to TS#70898

Open
kushagra-goyal-14 wants to merge 4 commits intoWordPress:trunkfrom
kushagra-goyal-14:try/migrate-keyboard-shortcuts-ts
Open

TypeScript: migrate keyboard-shortcuts package to TS#70898
kushagra-goyal-14 wants to merge 4 commits intoWordPress:trunkfrom
kushagra-goyal-14:try/migrate-keyboard-shortcuts-ts

Conversation

@kushagra-goyal-14
Copy link
Contributor

@kushagra-goyal-14 kushagra-goyal-14 commented Jul 24, 2025

What?

Part of #67691

Migrating the keyboard-shortcuts package to TypeScript.

Why?

To enhance DX and add type safety.

How?

By porting the code and tests to TypeScript.

Testing Instructions

Typecheck and unit tests.

@kushagra-goyal-14 kushagra-goyal-14 changed the title TypeScript: migrate keyboard-shortcut package to TS TypeScript: migrate keyboard-shortcuts package to TS Jul 24, 2025
@kushagra-goyal-14 kushagra-goyal-14 marked this pull request as ready for review July 24, 2025 14:05
@github-actions
Copy link

github-actions bot commented Jul 24, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kushagra-goyal-14 <[email protected]>
Co-authored-by: manzoorwanijk <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano mentioned this pull request Jul 25, 2025
40 tasks
@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Package] Keyboard Shortcuts /packages/keyboard-shortcuts labels Jul 25, 2025
Comment on lines 1 to 2
const useShortcut = (): null => null;
export default useShortcut;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to set the return type here. TS can inference it easily and it will preserve the git history for the file.

@kushagra-goyal-14
Copy link
Contributor Author

Updated the changes 🙌

Copy link
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I have some suggestions

Comment on lines +1 to +4
/**
* External dependencies
*/
import type { JSX } from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please directly use React.JSX without this import here like we have used React.HTMLAttributes below?

* @property {string} character Character.
* @property {WPKeycodeModifier|undefined} modifier Modifier.
*/
export interface WPShortcutKeyCombination {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us remove the WP prefix from the type here.

* @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.
* @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.
*/
export interface WPShortcutConfig {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us remove the WP prefix from the type here as well.

Comment on lines +6 to +13
interface ShortcutState {
category: string;
keyCombination: WPShortcutKeyCombination;
aliases?: WPShortcutKeyCombination[];
description: string;
}

type ShortcutsState = Record< string, ShortcutState >;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please move these types to a types.ts file? That means we will have less changes to the file and its git history will be preserved.

@manzoorwanijk
Copy link
Member

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Keyboard Shortcuts /packages/keyboard-shortcuts [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants