Skip to content

Commit

Permalink
#1866 remove any to unknown and cast
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Dec 16, 2024
1 parent 69511c7 commit 69f6526
Show file tree
Hide file tree
Showing 35 changed files with 157 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
import { ArchiveContext } from "../../../contexts/archive-context";
import useGlobalSettings from "../../../hooks/use-global-settings";
import useLocation from "../../../hooks/use-location/use-location";
import { IConnectionDefault } from "../../../interfaces/IConnectionDefault";
import { PageType } from "../../../interfaces/IDetailView";
import { IExifStatus } from "../../../interfaces/IExifStatus";
import { IFileIndexItem } from "../../../interfaces/IFileIndexItem";
Expand Down Expand Up @@ -87,8 +88,8 @@ const ArchiveSidebarLabelEditSearchReplace: React.FunctionComponent = () => {
return bodyParams;
}

function handleFetchPostResponse(anyData: { data: IFileIndexItem[] }) {
const result = new CastToInterface().InfoFileIndexArray(anyData.data);
function handleFetchPostResponse(anyData: IConnectionDefault) {
const result = new CastToInterface().InfoFileIndexArray(anyData.data as IFileIndexItem[]);
result.forEach((element) => {
if (element.status === IExifStatus.ReadOnly) setIsError(MessageWriteErrorReadOnly);
if (element.status === IExifStatus.NotFoundSourceMissing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export function SkipDisplayOfUpdate(): boolean {
*/
const HealthCheckForUpdates: FunctionComponent = () => {
const checkForUpdates = useFetch(new UrlQuery().UrlHealthCheckForUpdates(), "get");
const releaseInfo = useFetch(new UrlQuery().UrlHealthReleaseInfo(checkForUpdates.data), "get");
const releaseInfo = useFetch(
new UrlQuery().UrlHealthReleaseInfo(checkForUpdates.data as string),
"get"
);

const settings = useGlobalSettings();

Expand All @@ -53,7 +56,7 @@ const HealthCheckForUpdates: FunctionComponent = () => {
const MessageNewVersionUpdateHtml = language.token(
MessageNewVersionUpdateToken,
["{WhereToFindRelease}", "{otherInfo}"],
[WhereToFindRelease, releaseInfo.data]
[WhereToFindRelease, releaseInfo.data as string]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ const HealthStatusError: React.FunctionComponent = () => {
<span key="warning">{MessageHealthStatusCriticalErrors}</span>
];

if (!healthCheck.data?.entries) {
const healthCheckData = healthCheck.data as { entries: IHealthEntry[] };

if (!healthCheckData?.entries) {
content.push(
<li key="backend-services">BackendServices HTTP StatusCode: {healthCheck.statusCode}</li>
);
} else {
healthCheck.data.entries.forEach((entry: IHealthEntry) => {
healthCheckData.entries.forEach((entry: IHealthEntry) => {
if (entry.isHealthy) return;
content.push(<li key={entry.name}> {entry.name}</li>);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const InlineSearchSuggest: React.FunctionComponent<IInlineSearchSuggestProps> =
const history = useLocation();
const settings = useGlobalSettings();
const language = new Language(settings.language);
const dataFeatures = props.featuresResult?.data as IEnvFeatures | undefined;

useEffect(() => {
const dataFeatures = props.featuresResult?.data as IEnvFeatures | undefined;
if (dataFeatures?.systemTrashEnabled || dataFeatures?.useLocalDesktop) {
let newMenu = [...defaultMenu];
if (dataFeatures?.systemTrashEnabled) {
Expand All @@ -35,7 +35,7 @@ const InlineSearchSuggest: React.FunctionComponent<IInlineSearchSuggestProps> =
setDefaultMenu([...newMenu]);
}
// es_lint-disable-next-line react-hooks/exhaustive-deps // https://github.com/facebook/react/pull/30774
}, [props.featuresResult, props.featuresResult?.data?.systemTrashEnabled]);
}, [props.featuresResult, dataFeatures?.systemTrashEnabled]);

const [defaultMenu, setDefaultMenu] = useState([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { MemoryRouter } from "react-router-dom";
import * as useFetch from "../../../hooks/use-fetch";
import { IConnectionDefault, newIConnectionDefault } from "../../../interfaces/IConnectionDefault";
import { IEnvFeatures } from "../../../interfaces/IEnvFeatures";
import MenuInlineSearch from "./menu-inline-search";
import * as ArrowKeyDown from "./internal/arrow-key-down";
import * as InlineSearchSuggest from "./internal/inline-search-suggest";
import MenuInlineSearch from "./menu-inline-search";

describe("menu-inline-search", () => {
it("renders", () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("menu-inline-search", () => {
systemTrashEnabled: true,
useLocalDesktop: false
} as IEnvFeatures
} as IConnectionDefault;
};

it("default menu should show logout and trash in default mode", () => {
dataFeaturesExample.data.useLocalDesktop = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const MenuInlineSearch: FunctionComponent<IMenuSearchBarProps> = (props) => {
// can't set this inside effect or if ==> performance issue, runs to often
const responseObject = useFetch(new UrlQuery().UrlSearchSuggestApi(query), "get");
useEffect(() => {
if (!responseObject?.data?.length || responseObject.statusCode !== 200) {
if (!(responseObject?.data as string[])?.length || responseObject.statusCode !== 200) {
if (suggest && suggest.length >= 1) setSuggest([]);
return;
}
const result: Array<string> = [...responseObject.data];
const result: Array<string> = [...(responseObject?.data as string[])];
setSuggest(result);

// to avoid endless loops
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class UpdateChange {
item: IConnectionDefault,
resolve: (value: string | boolean | PromiseLike<string | boolean>) => void
) {
if (item.statusCode !== 200 || !item.data || item.data.length === 0) {
if (item.statusCode !== 200 || !item.data || (item.data as IFileIndexItem[]).length === 0) {
resolve("wrong status code or missing data");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,24 @@ const ModalArchiveSynchronizeManually: React.FunctionComponent<IModalDisplayOpti

function fetchGeoSyncStatus() {
const parentFolder = props.parentFolder ?? "/";
FetchGet(new UrlQuery().UrlGeoStatus(new URLPath().encodeURI(parentFolder))).then((anyData) => {
if (anyData.statusCode !== 200 || !anyData.data) {
setGeoSyncPercentage(-1);
return;
FetchGet(new UrlQuery().UrlGeoStatus(new URLPath().encodeURI(parentFolder))).then(
(anyData: unknown) => {
const containerData = anyData as {
statusCode: number;
data: { current: number; total: number };
};
if (containerData.statusCode !== 200 || !containerData.data) {
setGeoSyncPercentage(-1);
return;
}

if (containerData.data?.current === 0 && containerData.data.total === 0) {
setGeoSyncPercentage(0);
return;
}
setGeoSyncPercentage((containerData.data.current / containerData.data.total) * 100);
}

if (anyData.data.current === 0 && anyData.data.total === 0) {
setGeoSyncPercentage(0);
return;
}
setGeoSyncPercentage((anyData.data.current / anyData.data.total) * 100);
});
);
}

useInterval(() => fetchGeoSyncStatus(), 10000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const ModalDownload: React.FunctionComponent<IModalExportProps> = (props) => {
setIsProcessing(ProcessingState.fail);
return;
}
setCreateZipKey(zipKeyResult.data);
await ExportIntervalUpdate(zipKeyResult.data, setIsProcessing);
setCreateZipKey(zipKeyResult.data as string);
await ExportIntervalUpdate(zipKeyResult.data as string, setIsProcessing);
}

useInterval(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ModalEditDatetime: React.FunctionComponent<IModalDatetimeProps> = (props)

FetchPost(updateApiUrl, bodyParams.toString()).then((result) => {
if (result.statusCode !== 200) return;
props.handleExit(result.data);
props.handleExit(result.data as IFileIndexItem[]);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function UpdateGeoLocation(
new UrlQuery().UrlReverseLookup(location.latitude.toString(), location.longitude.toString())
);
if (reverseGeoCodeResult.statusCode === 200) {
model = reverseGeoCodeResult.data;
model = reverseGeoCodeResult.data as IGeoLocationModel;
bodyParams.append("locationCity", model.locationCity);
bodyParams.append("locationCountry", model.locationCountry);
bodyParams.append("locationCountryCode", model.locationCountryCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ModalMoveFile: React.FunctionComponent<IModalMoveFileProps> = (props) => {

const resultDo = await FetchPost(new UrlQuery().UrlDiskRename(), bodyParams.toString());

if (!resultDo.data || resultDo.data.length === 0 || !resultDo.data[0].status) {
if (!Array.isArray(resultDo.data) || resultDo.data.length === 0 || !resultDo.data[0].status) {
console.error("server error");
setError("Server error");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ModalMoveFolderToTrash: React.FunctionComponent<IModalMoveFolderToTrashPro
new CustomEvent<IApiNotificationResponseModel<IFileIndexItem[]>>(useSocketsEventName, {
bubbles: false,
detail: {
data: result.data,
data: result.data as IFileIndexItem[],
type: "move-folder-to-trash-internal"
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ const ModalPublish: React.FunctionComponent<IModalPublishProps> = (props) => {
setIsProcessing(ProcessingState.server);

const zipKeyResult = await FetchPost(new UrlQuery().UrlPublishCreate(), bodyParams.toString());
const zipKeyResultData = zipKeyResult.data as string;

if (zipKeyResult.statusCode !== 200 || !zipKeyResult.data) {
setIsProcessing(ProcessingState.fail);
return;
}
setCreateZipKey(zipKeyResult.data);
await ExportIntervalUpdate(zipKeyResult.data, setIsProcessing);
setCreateZipKey(zipKeyResultData);
await ExportIntervalUpdate(zipKeyResultData, setIsProcessing);
}

const allPublishProfiles = useFetch(new UrlQuery().UrlPublish(), "get").data as
Expand Down Expand Up @@ -100,7 +101,9 @@ const ModalPublish: React.FunctionComponent<IModalPublishProps> = (props) => {

FetchGet(new UrlQuery().UrlPublishExist(toUpdateItemName), CacheControl).then((result) => {
if (result.statusCode !== 200) return;
setExistItemName(result.data);

const resultData = result.data as boolean;
setExistItemName(resultData);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe("PreferencesAppSettingsDesktop", () => {
expect(formControlSpy).toHaveBeenCalledWith(
{
children: "/test",
contentEditable: undefined,
contentEditable: false,
name: "tags",
onBlur: expect.anything(),
spellcheck: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ const PreferencesAppSettingsDesktop: React.FunctionComponent = () => {
// roles
const permissionsData = useFetch(new UrlQuery().UrlAccountPermissions(), "get");

const isAppSettingsWrite = permissionsData?.data?.includes(
new UrlQuery().KeyAccountPermissionAppSettingsWrite()
);
const isAppSettingsWrite =
Array.isArray(permissionsData?.data) &&
permissionsData.data.includes(new UrlQuery().KeyAccountPermissionAppSettingsWrite());

const settings = useGlobalSettings();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ const PreferencesAppSettingsStorageFolder: React.FunctionComponent = () => {

useEffect(() => {
function permissions(): boolean {
if (!permissionsData?.data?.includes || permissionsData?.statusCode !== 200) {
const data = permissionsData?.data as string[];
if (!data?.includes || permissionsData?.statusCode !== 200) {
return false;
}
// AppSettingsWrite
return permissionsData.data.includes(new UrlQuery().KeyAccountPermissionAppSettingsWrite());
return data.includes(new UrlQuery().KeyAccountPermissionAppSettingsWrite());
}

setIsEnabled(permissions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const PreferencesPassword: React.FunctionComponent = () => {
bodyParams.toString()
);
setLoading(false);
if (response.statusCode === 200 && response.data?.success) {
if (response.statusCode === 200 && (response.data as { success: boolean }).success) {
setError(MessagePasswordChanged);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ const PreferencesUsername: React.FunctionComponent = () => {
const MessageUsername = language.key(localization.MessageUsername);
const MessageRole = language.key(localization.MessageRole);

interface AccountStatusData {
credentialsIdentifiers: string[];
roleCode: string;
}

const accountStatus = useFetch(new UrlQuery().UrlAccountStatus(), "get");
const accountStatusData = accountStatus?.data as AccountStatusData;

let userName = language.key(localization.MessageUnknownUsername);

if (accountStatus.statusCode === 200 && accountStatus?.data?.credentialsIdentifiers[0]) {
userName = accountStatus?.data?.credentialsIdentifiers[0];
if (accountStatus.statusCode === 200 && accountStatusData?.credentialsIdentifiers[0]) {
userName = accountStatusData?.credentialsIdentifiers[0];
if (userName === "mail@localhost") {
userName = language.key(localization.MessageDesktopMailLocalhostUsername);
}
Expand All @@ -31,7 +38,7 @@ const PreferencesUsername: React.FunctionComponent = () => {
{userName}
</div>
<div className="content--subheader">{MessageRole}</div>
<div className="content--text preferences-role">{accountStatus?.data?.roleCode}</div>
<div className="content--text preferences-role">{accountStatusData?.roleCode}</div>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ICurrentTouches } from "./ICurrentTouches.types";

export interface IHandlers {
onPanStart?: () => void;
onPanMove?: (ev: TouchEvent) => void;
Expand All @@ -14,3 +16,7 @@ export interface IHandlers {
onPinchChanged?: () => void;
onPinchEnd?: () => void;
}

export interface IHandlersMapper {
[key: string]: (event?: ICurrentTouches) => void;
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { ICurrentTouches } from "./ICurrentTouches.types";
import { IHandlers } from "./IHandlers.types";
import { callHandler } from "./call-handler";

describe("callHandler", () => {
describe("callHandler", () => {
it("should call test function", () => {
const handlers = { test: jest.fn() } as any;
callHandler("test", true as any, handlers);
const handlers = { test: jest.fn() } as unknown as IHandlers;
callHandler("test", true as unknown as ICurrentTouches, handlers);

expect(handlers.test).toHaveBeenCalled();
expect((handlers as { test: jest.Mock }).test).toHaveBeenCalled();
});

it("should not call test function", () => {
const handlers = { test: jest.fn() } as any;
callHandler(undefined as any, true as any, handlers);
const handlers = { test: jest.fn() } as unknown as IHandlers;
callHandler(undefined as unknown as string, true as unknown as ICurrentTouches, handlers);

expect(handlers.test).toHaveBeenCalledTimes(0);
expect((handlers as { test: jest.Mock }).test).toHaveBeenCalledTimes(0);
});
});

Expand Down
13 changes: 8 additions & 5 deletions starsky/starsky/clientapp/src/hooks/use-gestures/call-handler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { ICurrentTouches } from "./ICurrentTouches.types";
import { IHandlers } from "./IHandlers.types";
import { IHandlers, IHandlersMapper } from "./IHandlers.types";

export const callHandler = (
eventName: string,
event: ICurrentTouches,
handlers: IHandlers | undefined
handlers: IHandlers | undefined | IHandlersMapper
) => {
if (!handlers) {
throw new Error(`handler ${eventName} is missing`);
}

if (
eventName &&
(handlers as any)[eventName] &&
typeof (handlers as any)[eventName] === "function"
handlers[eventName as keyof IHandlers] &&
typeof handlers[eventName as keyof IHandlers] === "function"
) {
(handlers as any)[eventName](event);
const handler = handlers[eventName as keyof IHandlers];
if (handler) {
(handler as (e: ICurrentTouches) => void)(event);
}
}
};
6 changes: 3 additions & 3 deletions starsky/starsky/clientapp/src/hooks/use-gestures/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const debounce = (func: any, wait: number) => {
let timeout: any;
return function (...args: any) {
export const debounce = (func: (...args: unknown[]) => void, wait: number) => {
let timeout: ReturnType<typeof setTimeout>;
return function (...args: unknown[]) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-this-alias
Expand Down
Loading

0 comments on commit 69f6526

Please sign in to comment.