Skip to content

Commit

Permalink
fix: type guard to reduce amount of checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alashchev17 committed Dec 9, 2024
1 parent 2d07043 commit c3a8e4a
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ import { toPascalCase } from "../../../utils/toPascalCase";
import { debugIntegrations } from "../../../debugConfig";
import { iconMap } from "../icons/iconMap";

// TODO: should be extracted in the future
function jsonHasWhenIsolated(
json: unknown,
): json is Record<string, boolean> & { when_isolated: boolean } {
return (
typeof json === "object" &&
json !== null &&
"when_isolated" in json &&
typeof json.when_isolated === "boolean"
);
}

type IntegrationFormProps = {
integrationPath: string;
isApplying: boolean;
Expand Down Expand Up @@ -235,9 +247,7 @@ export const IntegrationForm: FC<IntegrationFormProps> = ({
</Flex>
)}
{integration.data.integr_schema.docker &&
integration.data.integr_values.available &&
typeof integration.data.integr_values.available === "object" &&
"when_isolated" in integration.data.integr_values.available &&
jsonHasWhenIsolated(integration.data.integr_values.available) &&
integration.data.integr_values.available.when_isolated && (
<Flex mt="6" direction="column" align="start" gap="5">
<Flex gap="2" align="center" justify="center" width="100%">
Expand Down

0 comments on commit c3a8e4a

Please sign in to comment.