KL-7 Improve typescript safety: disable allow any

This commit is contained in:
mbecker20
2025-12-01 12:17:22 -08:00
parent 581ef4f7da
commit 967629545f
10 changed files with 57 additions and 33 deletions

View File

@@ -57,6 +57,7 @@
"@types/react": "19.1.6",
"@types/react-dom": "19.1.5",
"@types/sanitize-html": "2.16.0",
"@types/shell-quote": "^1.7.5",
"@typescript-eslint/eslint-plugin": "8.33.0",
"@typescript-eslint/parser": "8.33.0",
"@vitejs/plugin-react": "4.5.0",

View File

@@ -456,7 +456,7 @@ const ProviderDialog = ({
: provider
) as Types.GitProvider[] | Types.DockerRegistry[],
});
const remove_account = (account_index) =>
const remove_account = (account_index: number) =>
set({
[arr_field]: providers.map(
(provider: Types.GitProvider | Types.DockerRegistry, provider_index) =>
@@ -495,7 +495,7 @@ const ProviderDialog = ({
: provider
) as Types.GitProvider[] | Types.DockerRegistry[],
});
const remove_organization = (organization_index) =>
const remove_organization = (organization_index: number) =>
set({
[arr_field]: providers.map(
(provider: Types.DockerRegistry, provider_index) =>

View File

@@ -552,9 +552,8 @@ const Stage = ({
execution: {
type,
params:
TARGET_COMPONENTS[
type as Types.Execution["type"]
].params,
TARGET_COMPONENTS[type as MinExecutionType]
.params,
},
} as Types.EnabledExecution)
: item
@@ -575,7 +574,8 @@ const Stage = ({
index,
},
}) => {
const Component = TARGET_COMPONENTS[type].Component;
const Component =
TARGET_COMPONENTS[type as MinExecutionType].Component;
return (
<Component
disabled={disabled}

View File

@@ -36,7 +36,11 @@ export const Prune = ({
? "pruning_system"
: "";
const pending = isPending || action_state?.[pruningKey];
const pending =
isPending ||
(pruningKey && action_state?.[pruningKey]
? action_state?.[pruningKey]
: undefined);
if (type === "Images" || type === "Networks" || type === "Buildx") {
return (

View File

@@ -507,9 +507,8 @@ export const useKeyListener = (listenKey: string, onPress: () => void) => {
useEffect(() => {
const keydown = (e: KeyboardEvent) => {
// This will ignore Shift + listenKey if it is sent from input / textarea
const target = e.target as any;
if (target.matches("input") || target.matches("textarea")) return;
const target = e.target as HTMLElement | null;
if (target?.matches("input") || target?.matches("textarea")) return;
if (e.key === listenKey) {
e.preventDefault();
onPress();
@@ -524,9 +523,8 @@ export const useShiftKeyListener = (listenKey: string, onPress: () => void) => {
useEffect(() => {
const keydown = (e: KeyboardEvent) => {
// This will ignore Shift + listenKey if it is sent from input / textarea
const target = e.target as any;
if (target.matches("input") || target.matches("textarea")) return;
const target = e.target as HTMLElement | null;
if (target?.matches("input") || target?.matches("textarea")) return;
if (e.shiftKey && e.key === listenKey) {
e.preventDefault();
onPress();

View File

@@ -45,7 +45,7 @@ export async function init_monaco() {
typeRoots: ["index.d.ts"],
allowTopLevelAwait: true,
moduleDetection: "force",
} as monaco.languages.typescript.CompilerOptions & ExtraOptions);
} as monaco.languages.typescript.CompilerOptions & Partial<ExtraOptions>);
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
diagnosticCodesToIgnore: [

View File

@@ -101,7 +101,7 @@ export default function AlertsPage() {
</SelectItem>
<SelectSeparator />
{Object.keys(ALERT_TYPES_BY_RESOURCE).map((type) => {
const Icon = ResourceComponents[type].Icon;
const Icon = ResourceComponents[type as UsableResource].Icon;
return (
<SelectItem key={type} value={type}>
<div className="flex items-center gap-2">

View File

@@ -1,19 +1,28 @@
export const Json = ({ json }: any) => {
type JsonValue =
| string
| number
| boolean
| null
| undefined
| JsonValue[]
| { [key: string]: JsonValue };
export const Json = ({ json }: { json: JsonValue }) => {
if (!json) {
return <p>null</p>;
}
const type = typeof json;
if (type === "function") {
return <p>??function??</p>;
}
// null case
if (type === "undefined") {
return <p>null</p>;
}
if (type === "function") {
return <p>??function??</p>;
}
// base cases
if (
type === "bigint" ||
@@ -22,27 +31,34 @@ export const Json = ({ json }: any) => {
type === "string" ||
type === "symbol"
) {
return <p>{json}</p>;
return <p>{String(json)}</p>;
}
// Type is object or array
if (Array.isArray(json)) {
return (
<div className="flex flex-col gap-2">
{(json as any[]).map((json) => (
<Json json={json} />
{json.map((json, index) => (
<Json key={index} json={json} />
))}
</div>
);
}
return (
<div className="flex flex-col gap-2">
{Object.keys(json).map((key) => (
<div className="flex gap-2">
<p>{key}</p>: <Json json={json[key]} />
</div>
))}
</div>
);
if (type === "object") {
const obj = json as {
[key: string]: JsonValue;
};
return (
<div className="flex flex-col gap-2">
{Object.keys(obj).map((key) => (
<div key={key} className="flex gap-2">
<p>{key}</p>: <Json json={obj[key]} />
</div>
))}
</div>
);
}
return <p>null</p>;
};

View File

@@ -21,7 +21,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": false,
"noImplicitAny": true,
/* Paths */
"baseUrl": "./src",
"paths": {

View File

@@ -1201,6 +1201,11 @@
resolved "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.8.tgz"
integrity sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==
"@types/shell-quote@^1.7.5":
version "1.7.5"
resolved "https://registry.yarnpkg.com/@types/shell-quote/-/shell-quote-1.7.5.tgz#6db4704742d307cd6d604e124e3ad6cd5ed943f3"
integrity sha512-+UE8GAGRPbJVQDdxi16dgadcBfQ+KG2vgZhV1+3A1XmHbmwcdwhCUwIdy+d3pAGrbvgRoVSjeI9vOWyq376Yzw==
"@typescript-eslint/eslint-plugin@8.33.0":
version "8.33.0"
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.33.0.tgz"