From 627ff2a71d5b12270caca37aee9ab93d209a8b5d Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Mon, 10 Aug 2026 14:51:10 +0200 Subject: [PATCH] [Glitch] Update to Typescript 7 Port ecf9d237529bd349c0cf64e46c07c8a30acfec13 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/actions/streaming.js | 22 +++++++++---------- .../components/account_header/buttons.tsx | 1 + .../glitch/components/account_header/menu.tsx | 1 + .../components/edited_timestamp/index.tsx | 4 +--- .../glitch/components/follow_button.tsx | 1 + .../glitch/components/remote_hint.tsx | 7 +----- .../directory/components/account_card.tsx | 2 +- .../flavours/glitch/hooks/useSearchTags.ts | 4 ++-- app/javascript/flavours/glitch/models/poll.ts | 4 ++-- .../glitch/reducers/notification_groups.ts | 2 +- .../glitch/reducers/slices/annual_report.ts | 10 +++++---- .../flavours/glitch/reducers/slices/emojis.ts | 14 +++++++----- app/javascript/flavours/glitch/stream.js | 16 +++++++------- 13 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/streaming.js b/app/javascript/flavours/glitch/actions/streaming.js index f4bd0ff373..22dc963fff 100644 --- a/app/javascript/flavours/glitch/actions/streaming.js +++ b/app/javascript/flavours/glitch/actions/streaming.js @@ -36,7 +36,7 @@ const randomUpTo = max => * @typedef {import('flavours/glitch/store').AppDispatch} Dispatch * @typedef {import('flavours/glitch/store').GetState} GetState * @typedef {import('redux').UnknownAction} UnknownAction - * @typedef {function(Dispatch, GetState): Promise} FallbackFunction + * @typedef {(dispatch: Dispatch, getState: GetState) => Promise} FallbackFunction */ /** @@ -45,9 +45,9 @@ const randomUpTo = max => * @param {Object.} params * @param {Object} options * @param {FallbackFunction} [options.fallback] - * @param {function(): UnknownAction} [options.fillGaps] - * @param {function(object): boolean} [options.accept] - * @returns {function(): void} + * @param {() => UnknownAction} [options.fillGaps] + * @param {(status: object) => boolean} [options.accept] + * @returns {() => void} */ export const connectTimelineStream = (timelineId, channelName, params = {}, options = {}) => { const { messages } = getLocale(); @@ -159,7 +159,7 @@ async function refreshHomeTimelineAndNotification(dispatch) { } /** - * @returns {function(): void} + * @returns {() => void} */ export const connectUserStream = () => connectTimelineStream('home', 'user', {}, { @@ -171,7 +171,7 @@ export const connectUserStream = () => /** * @param {Object} options * @param {boolean} [options.onlyMedia] - * @returns {function(): void} + * @returns {() => void} */ export const connectCommunityStream = ({ onlyMedia } = {}) => connectTimelineStream(`community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`, {}, { @@ -184,7 +184,7 @@ export const connectCommunityStream = ({ onlyMedia } = {}) => * @param {boolean} [options.onlyMedia] * @param {boolean} [options.onlyRemote] * @param {boolean} [options.allowLocalOnly] - * @returns {function(): void} + * @returns {() => void} */ export const connectPublicStream = ({ onlyMedia, onlyRemote, allowLocalOnly } = {}) => connectTimelineStream(`public${onlyRemote ? ':remote' : (allowLocalOnly ? ':allow_local_only' : '')}${onlyMedia ? ':media' : ''}`, `public${onlyRemote ? ':remote' : (allowLocalOnly ? ':allow_local_only' : '')}${onlyMedia ? ':media' : ''}`, {}, { @@ -196,21 +196,21 @@ export const connectPublicStream = ({ onlyMedia, onlyRemote, allowLocalOnly } = * @param {string} columnId * @param {string} tagName * @param {boolean} onlyLocal - * @param {function(object): boolean} accept - * @returns {function(): void} + * @param {(status: object) => boolean} accept + * @returns {() => void} */ export const connectHashtagStream = (columnId, tagName, onlyLocal, accept) => connectTimelineStream(`hashtag:${columnId}${onlyLocal ? ':local' : ''}`, `hashtag${onlyLocal ? ':local' : ''}`, { tag: tagName }, { accept }); /** - * @returns {function(): void} + * @returns {() => void} */ export const connectDirectStream = () => connectTimelineStream('direct', 'direct'); /** * @param {string} listId - * @returns {function(): void} + * @returns {() => void} */ export const connectListStream = listId => connectTimelineStream(`list:${listId}`, 'list', { list: listId }, { diff --git a/app/javascript/flavours/glitch/components/account_header/buttons.tsx b/app/javascript/flavours/glitch/components/account_header/buttons.tsx index 77003e71e3..9e342943c4 100644 --- a/app/javascript/flavours/glitch/components/account_header/buttons.tsx +++ b/app/javascript/flavours/glitch/components/account_header/buttons.tsx @@ -69,6 +69,7 @@ const AccountButtonsOther: FC< const dispatch = useAppDispatch(); const handleNotifyToggle = useCallback(() => { if (account) { + // @ts-expect-error this action is not typed yet dispatch(followAccount(account.id, { notify: !relationship?.notifying })); } }, [dispatch, account, relationship]); diff --git a/app/javascript/flavours/glitch/components/account_header/menu.tsx b/app/javascript/flavours/glitch/components/account_header/menu.tsx index 5dcf54c8de..ef771ebdba 100644 --- a/app/javascript/flavours/glitch/components/account_header/menu.tsx +++ b/app/javascript/flavours/glitch/components/account_header/menu.tsx @@ -398,6 +398,7 @@ function getMenuItems({ ), action: () => { dispatch( + // @ts-expect-error this action is not typed yet followAccount(account.id, { reblogs: !relationship.showing_reblogs, }), diff --git a/app/javascript/flavours/glitch/components/edited_timestamp/index.tsx b/app/javascript/flavours/glitch/components/edited_timestamp/index.tsx index bdffb79744..6e36401961 100644 --- a/app/javascript/flavours/glitch/components/edited_timestamp/index.tsx +++ b/app/javascript/flavours/glitch/components/edited_timestamp/index.tsx @@ -62,9 +62,7 @@ export const EditedTimestamp: React.FC<{ const formattedDate = ( ); - const formattedName = ( - - ); + const formattedName = ; const label = (item.get('original') as boolean) ? ( = ({ accountId }) => { accountId ? state.accounts.get(accountId) : undefined, ); const domain = account?.acct ? account.acct.split('@')[1] : undefined; - if ( - !account || - !account.url || - account.acct !== account.username || - !domain - ) { + if (!account?.url || account.acct !== account.username || !domain) { return null; } diff --git a/app/javascript/flavours/glitch/features/directory/components/account_card.tsx b/app/javascript/flavours/glitch/features/directory/components/account_card.tsx index ebfea75218..0648f95814 100644 --- a/app/javascript/flavours/glitch/features/directory/components/account_card.tsx +++ b/app/javascript/flavours/glitch/features/directory/components/account_card.tsx @@ -36,7 +36,7 @@ export const AccountCard: React.FC<{ accountId: string }> = ({ accountId }) => {
- +
diff --git a/app/javascript/flavours/glitch/hooks/useSearchTags.ts b/app/javascript/flavours/glitch/hooks/useSearchTags.ts index 51e81d6e33..05feacbc63 100644 --- a/app/javascript/flavours/glitch/hooks/useSearchTags.ts +++ b/app/javascript/flavours/glitch/hooks/useSearchTags.ts @@ -89,10 +89,10 @@ export function useSearchTags({ }, []); // Add dedicated item for adding the current query - const tags = useMemo(() => { + const tags = useMemo((): TagSearchResult[] => { const trimmedQuery = query ? trimHashFromStart(query.trim()) : ''; if (!trimmedQuery) { - return fetchedTags as TagSearchResult[]; + return fetchedTags; } const results: TagSearchResult[] = [...fetchedTags]; // Make array mutable diff --git a/app/javascript/flavours/glitch/models/poll.ts b/app/javascript/flavours/glitch/models/poll.ts index 7559e6f12c..7b94e54569 100644 --- a/app/javascript/flavours/glitch/models/poll.ts +++ b/app/javascript/flavours/glitch/models/poll.ts @@ -21,11 +21,11 @@ export interface PollOption extends ApiPollOptionJSON { export function createPollOptionTranslationFromServerJSON(translation: { title: string; -}) { +}): PollOptionTranslation { return { ...translation, titleHtml: escapeTextContentForBrowser(translation.title), - } as PollOptionTranslation; + }; } export interface Poll extends Omit< diff --git a/app/javascript/flavours/glitch/reducers/notification_groups.ts b/app/javascript/flavours/glitch/reducers/notification_groups.ts index 230b5a2de3..97cf05a296 100644 --- a/app/javascript/flavours/glitch/reducers/notification_groups.ts +++ b/app/javascript/flavours/glitch/reducers/notification_groups.ts @@ -371,7 +371,7 @@ function fillNotificationsGap( type: 'gap', maxId: notifications.at(-1)?.page_max_id, sinceId, - } as NotificationGap); + } satisfies NotificationGap); } // Remove older groups covered by the API diff --git a/app/javascript/flavours/glitch/reducers/slices/annual_report.ts b/app/javascript/flavours/glitch/reducers/slices/annual_report.ts index 23160a0f89..8ea868692d 100644 --- a/app/javascript/flavours/glitch/reducers/slices/annual_report.ts +++ b/app/javascript/flavours/glitch/reducers/slices/annual_report.ts @@ -24,12 +24,14 @@ interface AnnualReportState { report?: AnnualReport; } +const initialState: AnnualReportState = { + year: wrapstodon?.year, + state: wrapstodon?.state, +}; + const annualReportSlice = createSlice({ name: 'annualReport', - initialState: { - year: wrapstodon?.year, - state: wrapstodon?.state, - } as AnnualReportState, + initialState, reducers: { setReport(state, action: PayloadAction) { state.report = action.payload; diff --git a/app/javascript/flavours/glitch/reducers/slices/emojis.ts b/app/javascript/flavours/glitch/reducers/slices/emojis.ts index df19f23206..46331348ff 100644 --- a/app/javascript/flavours/glitch/reducers/slices/emojis.ts +++ b/app/javascript/flavours/glitch/reducers/slices/emojis.ts @@ -14,14 +14,16 @@ interface EmojisState { localesLoaded: Locale[]; } +const initialState: EmojisState = { + custom: {}, + customCategories: {}, + customLoaded: false, + localesLoaded: [], +}; + const emojisSlice = createSlice({ name: 'emojis', - initialState: { - custom: {}, - customCategories: {}, - customLoaded: false, - localesLoaded: [], - } as EmojisState, + initialState, reducers: { loadLocale(state, action: PayloadAction) { const locale = toSupportedLocale(action.payload); diff --git a/app/javascript/flavours/glitch/stream.js b/app/javascript/flavours/glitch/stream.js index e20abff86d..819cd3bf53 100644 --- a/app/javascript/flavours/glitch/stream.js +++ b/app/javascript/flavours/glitch/stream.js @@ -13,9 +13,9 @@ let sharedConnection; * @typedef Subscription * @property {string} channelName * @property {Object.} params - * @property {function(): void} onConnect - * @property {function(StreamEvent): void} onReceive - * @property {function(): void} onDisconnect + * @property {() => void} onConnect + * @property {(event: StreamEvent) => void} onReceive + * @property {() => void} onDisconnect */ /** @@ -146,8 +146,8 @@ const channelNameWithInlineParams = (channelName, params) => { /** * @param {string} channelName * @param {Object.} params - * @param {function(Dispatch, GetState): { onConnect: (function(): void), onReceive: (function(StreamEvent): void), onDisconnect: (function(): void) }} callbacks - * @returns {function(): void} + * @param {(dispatch: Dispatch, getState: GetState) => { onConnect: () => void, onReceive: (event: StreamEvent) => void, onDisconnect: () => void }} callbacks + * @returns {() => void} */ // @ts-expect-error export const connectStream = (channelName, params, callbacks) => (dispatch, getState) => { @@ -221,7 +221,7 @@ const KNOWN_EVENT_TYPES = [ /** * @param {MessageEvent} e - * @param {function(StreamEvent): void} received + * @param {(event: StreamEvent) => void} received */ const handleEventSourceMessage = (e, received) => { received({ @@ -234,7 +234,7 @@ const handleEventSourceMessage = (e, received) => { * @param {string} streamingAPIBaseURL * @param {string} accessToken * @param {string} channelName - * @param {{ connected: function(): void, received: function(StreamEvent): void, disconnected: function(): void, reconnected: function(): void }} callbacks + * @param {{ connected: () => void, received: (event: StreamEvent) => void, disconnected: () => void, reconnected: () => void }} callbacks * @returns {WebSocketClient | EventSource} */ const createConnection = (streamingAPIBaseURL, accessToken, channelName, { connected, received, disconnected, reconnected }) => { @@ -274,7 +274,7 @@ const createConnection = (streamingAPIBaseURL, accessToken, channelName, { conne es.addEventListener(type, e => handleEventSourceMessage(/** @type {MessageEvent} */(e), received)); }); - es.onerror = /** @type {function(): void} */ (disconnected); + es.onerror = /** @type {() => void} */ (disconnected); return es; };