From 4f3b6f36cf2a314ad2b1430434e7b75498efce26 Mon Sep 17 00:00:00 2001 From: Manzoor Wani Date: Fri, 30 Aug 2024 02:04:05 -0700 Subject: [PATCH] Social: Improve TS error reporting in publicize (#39133) --- pnpm-lock.yaml | 3 +++ .../changelog/update-improve-ts-error-reporting-in-publicize | 4 ++++ projects/js-packages/publicize-components/package.json | 1 + .../src/components/form/use-auto-save-and-redirect.ts | 1 + .../src/components/post-publish-share-status/index.tsx | 5 +++-- .../components/post-publish-share-status/share-status.tsx | 4 ++-- .../src/components/share-status/share-list.tsx | 4 ++-- .../src/hooks/use-post-pre-publish-value/index.ts | 4 ++-- 8 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 projects/js-packages/publicize-components/changelog/update-improve-ts-error-reporting-in-publicize diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4066146279aaf..3e3a0a1608320 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1084,6 +1084,9 @@ importers: '@types/react': specifier: 18.3.3 version: 18.3.3 + '@types/wordpress__editor': + specifier: 13.6.8 + version: 13.6.8(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@types/wordpress__media-utils': specifier: 4.14.4 version: 4.14.4(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) diff --git a/projects/js-packages/publicize-components/changelog/update-improve-ts-error-reporting-in-publicize b/projects/js-packages/publicize-components/changelog/update-improve-ts-error-reporting-in-publicize new file mode 100644 index 0000000000000..6978ee6e867e7 --- /dev/null +++ b/projects/js-packages/publicize-components/changelog/update-improve-ts-error-reporting-in-publicize @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Social: Improve ts error reporting in publicize diff --git a/projects/js-packages/publicize-components/package.json b/projects/js-packages/publicize-components/package.json index 4235dbb072f2c..88153b8ba3691 100644 --- a/projects/js-packages/publicize-components/package.json +++ b/projects/js-packages/publicize-components/package.json @@ -60,6 +60,7 @@ "@testing-library/user-event": "14.5.2", "@types/jest": "29.5.12", "@types/react": "18.3.3", + "@types/wordpress__editor": "13.6.8", "@types/wordpress__media-utils": "4.14.4", "@wordpress/babel-plugin-import-jsx-pragma": "5.5.0", "@wordpress/core-data": "7.5.0", diff --git a/projects/js-packages/publicize-components/src/components/form/use-auto-save-and-redirect.ts b/projects/js-packages/publicize-components/src/components/form/use-auto-save-and-redirect.ts index 9fd4daea5e49d..dea00097b5244 100644 --- a/projects/js-packages/publicize-components/src/components/form/use-auto-save-and-redirect.ts +++ b/projects/js-packages/publicize-components/src/components/form/use-auto-save-and-redirect.ts @@ -9,6 +9,7 @@ import { useCallback } from '@wordpress/element'; * @return {Function} Function to handle autosaving and redirecting. */ export function useAutoSaveAndRedirect(): React.DOMAttributes< HTMLAnchorElement >[ 'onClick' ] { + // @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript const { isEditedPostDirty } = useSelect( editorStore, [] ); const { autosave } = useDispatch( editorStore ); diff --git a/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx b/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx index 72a6565312f65..85b8b5a1c2846 100644 --- a/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx +++ b/projects/js-packages/publicize-components/src/components/post-publish-share-status/index.tsx @@ -16,12 +16,13 @@ export function PostPublishShareStatus() { const { featureFlags, postId, isPostPublised } = useSelect( select => { const store = select( socialStore ); - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript - const _editorStore = select( editorStore ) as any; + const _editorStore = select( editorStore ); return { featureFlags: store.featureFlags(), + // @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript postId: _editorStore.getCurrentPostId(), + // @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript isPostPublised: _editorStore.isCurrentPostPublished(), }; }, [] ); diff --git a/projects/js-packages/publicize-components/src/components/post-publish-share-status/share-status.tsx b/projects/js-packages/publicize-components/src/components/post-publish-share-status/share-status.tsx index a88b2bb00a21d..fb951128bb71c 100644 --- a/projects/js-packages/publicize-components/src/components/post-publish-share-status/share-status.tsx +++ b/projects/js-packages/publicize-components/src/components/post-publish-share-status/share-status.tsx @@ -30,8 +30,8 @@ export function ShareStatus( { postId }: ShareStatusProps ) { // Whether the post has been published more than one minute ago. const hasBeenMoreThanOneMinute = useSelect( select => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript - const date = ( select( editorStore ) as any ).getEditedPostAttribute( 'date' ); + // @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript + const date = select( editorStore ).getEditedPostAttribute( 'date' ); const oneMinuteAfterPostDate = new Date( Number( getDate( date ) ) + ONE_MINUTE_IN_MS ); diff --git a/projects/js-packages/publicize-components/src/components/share-status/share-list.tsx b/projects/js-packages/publicize-components/src/components/share-status/share-list.tsx index 90714ab167389..8875e7fc1c772 100644 --- a/projects/js-packages/publicize-components/src/components/share-status/share-list.tsx +++ b/projects/js-packages/publicize-components/src/components/share-status/share-list.tsx @@ -14,10 +14,10 @@ import styles from './styles.module.scss'; export function ShareList() { const { shareStatus } = useSelect( select => { const store = select( socialStore ); - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript - const _editorStore = select( editorStore ) as any; + const _editorStore = select( editorStore ); return { + // @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript shareStatus: store.getPostShareStatus( _editorStore.getCurrentPostId() ), }; }, [] ); diff --git a/projects/js-packages/publicize-components/src/hooks/use-post-pre-publish-value/index.ts b/projects/js-packages/publicize-components/src/hooks/use-post-pre-publish-value/index.ts index 60d80b8b9d97f..8ba9f12d8be38 100644 --- a/projects/js-packages/publicize-components/src/hooks/use-post-pre-publish-value/index.ts +++ b/projects/js-packages/publicize-components/src/hooks/use-post-pre-publish-value/index.ts @@ -14,8 +14,8 @@ import { useEffect, useRef, useState } from '@wordpress/element'; */ export function usePostPrePublishValue< V >( value: V ) { const isPublishing = useSelect( - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- `@wordpress/editor` is a nightmare to work with TypeScript - select => ( select( editorStore ) as any ).isPublishingPost(), + // @ts-expect-error -- `@wordpress/editor` is a nightmare to work with TypeScript + select => select( editorStore ).isPublishingPost(), [] );