From 34886819729f83edb16a959d6da46e74fafef629 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Mon, 2 Dec 2024 13:52:16 +0530 Subject: [PATCH 1/3] Upgrade TypeScript to 5.7 and fix types --- package-lock.json | 8 ++++---- package.json | 2 +- packages/components/src/dropdown-menu/index.tsx | 4 +++- packages/components/src/modal/test/index.tsx | 3 ++- packages/components/src/tree-grid/cell.tsx | 6 +++++- packages/components/src/tree-grid/types.ts | 2 +- packages/rich-text/src/create.js | 13 +++++++++++++ packages/router/src/router.tsx | 2 -- packages/vips/README.md | 4 ++-- packages/vips/src/index.ts | 6 +++--- 10 files changed, 34 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 98865c9d041a58..213c59578a147c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -153,7 +153,7 @@ "style-loader": "3.2.1", "terser": "5.32.0", "terser-webpack-plugin": "5.3.10", - "typescript": "5.5.3", + "typescript": "5.7.2", "uuid": "9.0.1", "webdriverio": "8.16.20", "webpack": "5.95.0", @@ -48699,9 +48699,9 @@ } }, "node_modules/typescript": { - "version": "5.5.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", - "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index 46a04a52aa6077..85be1e16a161de 100644 --- a/package.json +++ b/package.json @@ -162,7 +162,7 @@ "style-loader": "3.2.1", "terser": "5.32.0", "terser-webpack-plugin": "5.3.10", - "typescript": "5.5.3", + "typescript": "5.7.2", "uuid": "9.0.1", "webdriverio": "8.16.20", "webpack": "5.95.0", diff --git a/packages/components/src/dropdown-menu/index.tsx b/packages/components/src/dropdown-menu/index.tsx index 0e4501be4839c0..a876ec61918174 100644 --- a/packages/components/src/dropdown-menu/index.tsx +++ b/packages/components/src/dropdown-menu/index.tsx @@ -168,7 +168,9 @@ function UnconnectedDropdownMenu( dropdownMenuProps: DropdownMenuProps ) { indexOfSet, indexOfControl, ].join() } - onClick={ ( event ) => { + onClick={ ( + event: React.MouseEvent< HTMLButtonElement > + ) => { event.stopPropagation(); props.onClose(); if ( control.onClick ) { diff --git a/packages/components/src/modal/test/index.tsx b/packages/components/src/modal/test/index.tsx index a0d0ee2653edb4..05dcc35dce18da 100644 --- a/packages/components/src/modal/test/index.tsx +++ b/packages/components/src/modal/test/index.tsx @@ -269,7 +269,8 @@ describe( 'Modal', () => { } ); describe( 'Focus handling', () => { - let originalGetClientRects: () => DOMRectList; + const originalGetClientRects = + window.HTMLElement.prototype.getClientRects; const FocusMountDemo = ( { focusOnMount, diff --git a/packages/components/src/tree-grid/cell.tsx b/packages/components/src/tree-grid/cell.tsx index a9883eb0512266..08261abe10313a 100644 --- a/packages/components/src/tree-grid/cell.tsx +++ b/packages/components/src/tree-grid/cell.tsx @@ -21,7 +21,11 @@ function UnforwardedTreeGridCell( return ( { withoutGridItem ? ( - <>{ children } + <> + { typeof children === 'function' + ? children( { ...props, ref } ) + : children } + ) : ( { children } ) } diff --git a/packages/components/src/tree-grid/types.ts b/packages/components/src/tree-grid/types.ts index 31d04882d1a815..f4946ba58ca8a0 100644 --- a/packages/components/src/tree-grid/types.ts +++ b/packages/components/src/tree-grid/types.ts @@ -36,7 +36,7 @@ export type TreeGridRowProps = { type RovingTabIndexItemPassThruProps = { ref: React.ForwardedRef< any >; tabIndex?: number; - onFocus: React.FocusEventHandler< any >; + onFocus?: React.FocusEventHandler< any >; [ key: string ]: any; }; diff --git a/packages/rich-text/src/create.js b/packages/rich-text/src/create.js index d683836d9e2fa8..a8fc4b92c49600 100644 --- a/packages/rich-text/src/create.js +++ b/packages/rich-text/src/create.js @@ -125,6 +125,13 @@ export class RichTextData { static fromHTMLString( html ) { return new RichTextData( create( { html } ) ); } + /** + * Create a RichTextData instance from an HTML element. + * + * @param {HTMLElement} htmlElement The HTML element to create the instance from. + * @param {{preserveWhiteSpace?: boolean}} options Options. + * @return {RichTextData} The RichTextData instance. + */ static fromHTMLElement( htmlElement, options = {} ) { const { preserveWhiteSpace = false } = options; const element = preserveWhiteSpace @@ -144,6 +151,12 @@ export class RichTextData { } // We could expose `toHTMLElement` at some point as well, but we'd only use // it internally. + /** + * Convert the rich text value to an HTML string. + * + * @param {{preserveWhiteSpace?: boolean}} options Options. + * @return {string} The HTML string. + */ toHTMLString( { preserveWhiteSpace } = {} ) { return ( this.originalHTML || diff --git a/packages/router/src/router.tsx b/packages/router/src/router.tsx index 34cc542c7b5737..324d6c37f72258 100644 --- a/packages/router/src/router.tsx +++ b/packages/router/src/router.tsx @@ -120,7 +120,6 @@ export function useHistory() { window.matchMedia( '(min-width: 782px)' ).matches; if ( ! isMediumOrBigger || - // @ts-expect-error ! document.startViewTransition || ! options.transition ) { @@ -131,7 +130,6 @@ export function useHistory() { await new Promise< void >( ( resolve ) => { const classname = options.transition ?? ''; document.documentElement.classList.add( classname ); - // @ts-expect-error const transition = document.startViewTransition( () => performPush() ); diff --git a/packages/vips/README.md b/packages/vips/README.md index d7bf6001b51027..fe367e3bb6490c 100644 --- a/packages/vips/README.md +++ b/packages/vips/README.md @@ -42,7 +42,7 @@ _Parameters_ _Returns_ -- `Promise< ArrayBuffer >`: Compressed file data. +- `Promise< ArrayBuffer | ArrayBufferLike >`: Compressed file data. ### convertImageFormat @@ -83,7 +83,7 @@ _Parameters_ _Returns_ -- `Promise< { buffer: ArrayBuffer; width: number; height: number; originalWidth: number; originalHeight: number; } >`: Processed file data plus the old and new dimensions. +- `Promise< { buffer: ArrayBuffer | ArrayBufferLike; width: number; height: number; originalWidth: number; originalHeight: number; } >`: Processed file data plus the old and new dimensions. ### setLocation diff --git a/packages/vips/src/index.ts b/packages/vips/src/index.ts index 5dffe1f0808f28..dcd1858f0e57fb 100644 --- a/packages/vips/src/index.ts +++ b/packages/vips/src/index.ts @@ -122,7 +122,7 @@ export async function convertImageFormat( outputType: string, quality = 0.82, interlaced = false -): Promise< ArrayBuffer > { +): Promise< ArrayBuffer | ArrayBufferLike > { const ext = outputType.split( '/' )[ 1 ]; inProgressOperations.add( id ); @@ -186,7 +186,7 @@ export async function compressImage( type: string, quality = 0.82, interlaced = false -): Promise< ArrayBuffer > { +): Promise< ArrayBuffer | ArrayBufferLike > { return convertImageFormat( id, buffer, type, type, quality, interlaced ); } @@ -207,7 +207,7 @@ export async function resizeImage( resize: ImageSizeCrop, smartCrop = false ): Promise< { - buffer: ArrayBuffer; + buffer: ArrayBuffer | ArrayBufferLike; width: number; height: number; originalWidth: number; From 12b33b6f5e4d1f1a083583ab024e6e96de6e6c36 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Fri, 6 Dec 2024 11:02:01 +0530 Subject: [PATCH 2/3] Increase the minimum required version of TypeScript for the ESLint config package --- package-lock.json | 2 +- packages/eslint-plugin/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 213c59578a147c..9130d9432010ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54648,7 +54648,7 @@ "@babel/core": ">=7", "eslint": ">=8", "prettier": ">=3", - "typescript": ">=4" + "typescript": ">=5" }, "peerDependenciesMeta": { "prettier": { diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 64c0a422873d69..1e75a2c131f229 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -53,7 +53,7 @@ "@babel/core": ">=7", "eslint": ">=8", "prettier": ">=3", - "typescript": ">=4" + "typescript": ">=5" }, "peerDependenciesMeta": { "prettier": { From 6a7bebfe250f6158a37705defbe82812b5af697f Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Fri, 6 Dec 2024 11:53:40 +0530 Subject: [PATCH 3/3] Update CHANGELOG.md --- packages/eslint-plugin/CHANGELOG.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 91b517249b597a..a53fe75dee448f 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Breaking Changes + +- The minimum required TypeScript version changed to 5 ([#67461](https://github.com/WordPress/gutenberg/pull/67461)) + ## 21.6.0 (2024-11-27) ## 21.5.0 (2024-11-16) @@ -18,8 +22,8 @@ ### Breaking Changes -- Add [`@wordpress/i18n-no-flanking-whitespace`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/i18n-no-flanking-whitespace.md) to the recommended i18n ruleset ([#64710](https://github.com/WordPress/gutenberg/pull/64710). -- Add [`@wordpress/i18n-hyphenated-range`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/i18n-hyphenated-range.md) to the recommended i18n ruleset ([#64710](https://github.com/WordPress/gutenberg/pull/64710). +- Add [`@wordpress/i18n-no-flanking-whitespace`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/i18n-no-flanking-whitespace.md) to the recommended i18n ruleset ([#64710](https://github.com/WordPress/gutenberg/pull/64710). +- Add [`@wordpress/i18n-hyphenated-range`](https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/i18n-hyphenated-range.md) to the recommended i18n ruleset ([#64710](https://github.com/WordPress/gutenberg/pull/64710). ## 20.3.0 (2024-08-21) @@ -30,8 +34,9 @@ ## 20.0.0 (2024-07-10) ### Breaking Changes -- Add [`@typescript-eslint/no-unused-vars` rule](https://typescript-eslint.io/rules/no-unused-vars) to the recommended TypeScript ruleset ([#62925](https://github.com/WordPress/gutenberg/pull/62925)). -- Add [`@typescript-eslint/method-signature-style` rule](https://typescript-eslint.io/rules/method-signature-style) to the recommended TypeScript ruleset ([#62718](https://github.com/WordPress/gutenberg/pull/62718)). + +- Add [`@typescript-eslint/no-unused-vars` rule](https://typescript-eslint.io/rules/no-unused-vars) to the recommended TypeScript ruleset ([#62925](https://github.com/WordPress/gutenberg/pull/62925)). +- Add [`@typescript-eslint/method-signature-style` rule](https://typescript-eslint.io/rules/method-signature-style) to the recommended TypeScript ruleset ([#62718](https://github.com/WordPress/gutenberg/pull/62718)). ## 19.2.0 (2024-06-26)