1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-27 14:28:53 +09:00

refactor(frontend): scripts/form.tsの型定義を修正してTS2344/TS2345エラーを削減 (#12913)

This commit is contained in:
zyoshoka 2024-01-06 18:43:28 +09:00 committed by GitHub
parent 24645e3d3d
commit b55a6a80e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
type EnumItem = string | {label: string; value: string;};
type EnumItem = string | {
label: string;
value: string;
};
export type FormItem = {
label?: string;
type: 'string';
@ -36,16 +40,23 @@ export type FormItem = {
label: string;
value: unknown;
}[];
} | {
label?: string;
type: 'range';
default: number | null;
step: number;
min: number;
max: number;
} | {
label?: string;
type: 'object';
default: Record<string, unknown> | null;
hidden: true;
hidden: boolean;
} | {
label?: string;
type: 'array';
default: unknown[] | null;
hidden: true;
hidden: boolean;
};
export type Form = Record<string, FormItem>;
@ -55,6 +66,7 @@ type GetItemType<Item extends FormItem> =
Item['type'] extends 'number' ? number :
Item['type'] extends 'boolean' ? boolean :
Item['type'] extends 'radio' ? unknown :
Item['type'] extends 'range' ? number :
Item['type'] extends 'enum' ? string :
Item['type'] extends 'array' ? unknown[] :
Item['type'] extends 'object' ? Record<string, unknown>