Skip to content

Commit

Permalink
another portion of types
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed May 21, 2024
1 parent 9f96e0c commit d96b217
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/actions/javascript/bumpVersion/bumpVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function updateNativeVersions(version: string) {
.then(() => {
console.log('Successfully updated Android!');
})
.catch((err) => {
.catch((err: string | Error) => {
console.error('Error updating Android');
core.setFailed(err);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const run = function (): Promise<void> {
core.setOutput('HAS_DEPLOY_BLOCKERS', false);
}
})
.catch((error) => {
.catch((error: string | Error) => {
console.error('A problem occurred while trying to communicate with the GitHub API', error);
core.setFailed(error);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as core from '@actions/core';
import {readFileSync} from 'fs';
import type {PackageJson} from 'type-fest';
import * as versionUpdater from '@github/libs/versionUpdater';

const semverLevel = core.getInput('SEMVER_LEVEL', {required: true});
if (!semverLevel || !Object.values<string>(versionUpdater.SEMANTIC_VERSION_LEVELS).includes(semverLevel)) {
core.setFailed(`'Error: Invalid input for 'SEMVER_LEVEL': ${semverLevel}`);
}

const {version: currentVersion}: {version: string} = JSON.parse(readFileSync('./package.json', 'utf8'));
const previousVersion = versionUpdater.getPreviousVersion(currentVersion, semverLevel);
const {version: currentVersion}: PackageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
if (!currentVersion) {
core.setFailed('Error: Could not read package.json');
}

const previousVersion = versionUpdater.getPreviousVersion(currentVersion ?? '', semverLevel);
core.setOutput('PREVIOUS_VERSION', previousVersion);
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems: number) {

getNumberOfItemsFromReviewerChecklist()
.then(checkIssueForCompletedChecklist)
.catch((err) => {
.catch((err: string | Error) => {
console.error(err);
core.setFailed(err);
});
2 changes: 1 addition & 1 deletion src/components/AttachmentPicker/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s
*/
const showDocumentPicker = useCallback(
(): Promise<DocumentPickerResponse[] | void> =>
RNDocumentPicker.pick(getDocumentPickerOptions(type)).catch((error) => {
RNDocumentPicker.pick(getDocumentPickerOptions(type)).catch((error: TypeError) => {
if (RNDocumentPicker.isCancel(error)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function Composer(
if (shouldCalculateCaretPosition && isRendered) {
// we do flushSync to make sure that the valueBeforeCaret is updated before we calculate the caret position to receive a proper position otherwise we will calculate position for the previous state
flushSync(() => {
setValueBeforeCaret(webEvent.target.value.slice(0, webEvent.nativeEvent.selection.start));
setValueBeforeCaret((webEvent.target as HTMLInputElement).value.slice(0, webEvent.nativeEvent.selection.start));
setCaretContent(getNextChars(value ?? '', webEvent.nativeEvent.selection.start));
});
const selectionValue = {
Expand Down
5 changes: 4 additions & 1 deletion src/components/Icon/__mocks__/Expensicons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const Expensicons = jest.requireActual('../Expensicons');
// eslint-disable-next-line import/no-import-module-exports
import type {SvgProps} from 'react-native-svg';

const Expensicons = jest.requireActual<Record<string, React.FC<SvgProps>>>('../Expensicons');

module.exports = Object.keys(Expensicons).reduce((prev, curr) => {
// We set the name of the anonymous mock function here so we can dynamically build the list of mocks and access the
Expand Down
7 changes: 4 additions & 3 deletions src/components/SignInButtons/AppleSignIn/index.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import appleAuth from '@invertase/react-native-apple-authentication';
import type {AppleError} from '@invertase/react-native-apple-authentication';
import React from 'react';
import IconButton from '@components/SignInButtons/IconButton';
import Log from '@libs/Log';
Expand Down Expand Up @@ -35,11 +36,11 @@ function AppleSignIn() {
const handleSignIn = () => {
appleSignInRequest()
.then((token) => Session.beginAppleSignIn(token))
.catch((e) => {
if (e.code === appleAuth.Error.CANCELED) {
.catch((error: {code: AppleError}) => {
if (error.code === appleAuth.Error.CANCELED) {
return null;
}
Log.alert('[Apple Sign In] Apple authentication failed', e);
Log.alert('[Apple Sign In] Apple authentication failed', error);
});
};
return (
Expand Down
10 changes: 7 additions & 3 deletions src/libs/Pusher/pusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ type PusherEventMap = {
[TYPE.USER_IS_LEAVING_ROOM]: UserIsLeavingRoomEvent;
};

type EventData<EventName extends string> = EventName extends keyof PusherEventMap ? PusherEventMap[EventName] : OnyxUpdatesFromServer;
type EventData<EventName extends string> = {chunk?: string; id?: string; index?: number; final?: boolean} & (EventName extends keyof PusherEventMap
? PusherEventMap[EventName]
: OnyxUpdatesFromServer);

type EventCallbackError = {type: ValueOf<typeof CONST.ERROR>; data: {code: number}};

Expand Down Expand Up @@ -164,7 +166,7 @@ function bindEventToChannel<EventName extends PusherEventName>(channel: Channel
return;
}

let data;
let data: EventData<EventName>;
try {
data = isObject(eventData) ? eventData : JSON.parse(eventData);
} catch (err) {
Expand All @@ -187,7 +189,9 @@ function bindEventToChannel<EventName extends PusherEventName>(channel: Channel

// Add it to the rolling list.
const chunkedEvent = chunkedDataEvents[data.id];
chunkedEvent.chunks[data.index] = data.chunk;
if (data.index !== undefined) {
chunkedEvent.chunks[data.index] = data.chunk;
}

// If this is the last packet, mark that we've hit the end.
if (data.final) {
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {addSeconds, format, subMinutes, subSeconds} from 'date-fns';
import {utcToZonedTime} from 'date-fns-tz';
import React from 'react';
import {AppState, DeviceEventEmitter, Linking} from 'react-native';
import type {ViewStyle} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type Animated from 'react-native-reanimated';
Expand Down Expand Up @@ -157,7 +158,10 @@ function scrollUpToRevealNewMessagesBadge() {
function isNewMessagesBadgeVisible(): boolean {
const hintText = Localize.translateLocal('accessibilityHints.scrollToNewestMessages');
const badge = screen.queryByAccessibilityHint(hintText);
return Math.round(badge?.props.style.transform[0].translateY) === -40;
const badgeProps = badge?.props as {style: ViewStyle};
const transformStyle = badgeProps.style.transform?.[0] as {translateY: number};

return Math.round(transformStyle.translateY) === -40;
}

function navigateToSidebar(): Promise<void> {
Expand Down
19 changes: 9 additions & 10 deletions tests/utils/collections/reportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import {rand, randAggregation, randBoolean, randWord} from '@ngneat/falso';
import {format} from 'date-fns';
import CONST from '@src/CONST';
import type {ReportAction} from '@src/types/onyx';
import type {ActionName} from '@src/types/onyx/OriginalMessage';
import type DeepRecord from '@src/types/utils/DeepRecord';

type ActionType = keyof typeof CONST.REPORT.ACTIONS.TYPE;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const flattenActionNamesValues = (actionNames: any) => {
let result = [] as ActionType[];
Object.keys(actionNames).forEach((key) => {
if (typeof actionNames[key] === 'object') {
result = result.concat(flattenActionNamesValues(actionNames[key]));
const flattenActionNamesValues = (actionNames: DeepRecord<string, ActionName>) => {
let result: ActionName[] = [];
Object.values(actionNames).forEach((value) => {
if (typeof value === 'object') {
result = result.concat(flattenActionNamesValues(value));
} else {
result.push(actionNames[key]);
result.push(value);
}
});
return result;
Expand Down Expand Up @@ -81,4 +80,4 @@ export default function createRandomReportAction(index: number): ReportAction {
};
}

export {getRandomDate};
export {getRandomDate, flattenActionNamesValues};

0 comments on commit d96b217

Please sign in to comment.