Skip to content

Commit 9f6c7ed

Browse files
fix: clear up tauri configuration value typing
(cherry picked from commit ae0a592)
1 parent 20c31f7 commit 9f6c7ed

1 file changed

Lines changed: 22 additions & 36 deletions

File tree

clients/web/src/components/tauri/configuration-value.tsx

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,43 @@
1-
import { Show, For, Switch, Match } from "solid-js";
1+
import { Show, For, createMemo } from "solid-js";
22
import { ConfigurationTooltip } from "./configuration-tooltip";
33
import { Flags } from "./configuration-value/flags";
4+
import { TauriConfig } from "~/lib/tauri/config/tauri-conf";
45

5-
type ConfigurationValue =
6-
| ConfigurationRecord
7-
| string
8-
| []
9-
| boolean
10-
| null
11-
| undefined
12-
| unknown;
13-
14-
/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
15-
interface ConfigurationRecord extends Record<string, ConfigurationValue> {}
6+
type ConfigurationValue = TauriConfig[keyof TauriConfig];
167

178
interface ConfigurationValueProps {
189
parentKey: string;
1910
key: string;
2011
value: ConfigurationValue;
2112
}
2213

23-
interface TextConfigurationValueProps extends ConfigurationValueProps {
14+
type TextConfigurationValueProps = Omit<ConfigurationValueProps, "value"> & {
2415
value: string | boolean;
25-
}
16+
};
2617

2718
interface ArrayConfigurationValueProps extends ConfigurationValueProps {
28-
value: [];
19+
value: ConfigurationValue[];
2920
}
3021

3122
interface ObjectConfigurationValueProps extends ConfigurationValueProps {
32-
value: ConfigurationRecord;
23+
value: Omit<ConfigurationValue, "undefined">;
3324
}
3425

3526
export function ConfigurationValue(props: ConfigurationValueProps) {
36-
return (
37-
<Switch
38-
fallback={<TextValue {...(props as TextConfigurationValueProps)} />}
39-
>
40-
<Match
41-
when={
42-
typeof props.value === "string" || typeof props.value === "boolean"
43-
}
44-
>
45-
<TextValue {...(props as TextConfigurationValueProps)} />
46-
</Match>
47-
<Match when={Array.isArray(props.value)}>
48-
<ArrayValue {...(props as ArrayConfigurationValueProps)} />
49-
</Match>
50-
<Match when={typeof props.value === "object" && props.value !== null}>
51-
<ObjectValue {...(props as ObjectConfigurationValueProps)} />
52-
</Match>
53-
</Switch>
54-
);
27+
const selectedTemplate = createMemo(() => {
28+
if (typeof props.value === "string" || typeof props.value === "boolean")
29+
return <TextValue {...props} value={props.value} />;
30+
31+
if (Array.isArray(props.value))
32+
return <ArrayValue {...props} value={props.value} />;
33+
34+
if (typeof props.value === "object" && props.value)
35+
return <ObjectValue {...props} value={props.value} />;
36+
37+
return <TextValue {...props} value={String(props.value)} />;
38+
});
39+
40+
return <>{selectedTemplate()}</>;
5541
}
5642

5743
function TextValue(props: TextConfigurationValueProps) {
@@ -84,7 +70,7 @@ function ObjectValue(props: ObjectConfigurationValueProps) {
8470
<ConfigurationTooltip parentKey={props.parentKey} key={props.key} />
8571
</h2>
8672
<ul class="flex flex-col">
87-
<For each={Object.entries(props.value)}>
73+
<For each={Object.entries<ConfigurationValue>(props.value)}>
8874
{([childKey, value]) => (
8975
<li>
9076
<ConfigurationValue

0 commit comments

Comments
 (0)