refactor: update field schema types

This commit is contained in:
2026-09-05 16:16:10 +05:00
parent 19f2e13b88
commit 743ae817ee
2 changed files with 42 additions and 19 deletions
+20 -9
View File
@@ -76,15 +76,26 @@ export interface ColorPairSpec {
to: string;
}
export type FieldSpec =
| NumberSpec
| SliderSpec
| ColorSpec
| SelectSpec
| TextSpec
| CheckboxSpec
| DimensionSpec
| ColorPairSpec;
/**
* «Объект as const» kind → спека поля. Единственный источник правды для
* перечня kinds: `FieldSpecKind` = ключи map, `FieldSpec` = значение по любому
* ключу (тот же union). Добавляем новый составной тип — добавляем сюда, и
* type-checker укажет, где его не хватает (record контролов, default/sanitize).
*/
export const fieldSpecs = {
number: {} as NumberSpec,
slider: {} as SliderSpec,
color: {} as ColorSpec,
select: {} as SelectSpec,
text: {} as TextSpec,
checkbox: {} as CheckboxSpec,
dimension: {} as DimensionSpec,
"color-pair": {} as ColorPairSpec,
} as const;
export type FieldSpecKind = keyof typeof fieldSpecs;
export type FieldSpecOf<K extends FieldSpecKind> = (typeof fieldSpecs)[K];
export type FieldSpec = FieldSpecOf<FieldSpecKind>;
/** `Field<T>`: runtime-спека поля + phantom-тип ожидаемого значения (number|string|boolean). */
export interface Field<T> {