From dc19898cee7988834151bac217dd6fc052583041 Mon Sep 17 00:00:00 2001 From: Vladislav Date: Wed, 13 Mar 2024 11:17:11 +0200 Subject: [PATCH] Some code comments fixes --- src/index.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4c69bfd..976a9bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ export type FormModel< TAnnotations extends Record | null = null, > = FormModelInnerTraverse -// Special type for annotation +// Special type for annotation to completely replace inferred type export type Replace = T & { __replace__: '__replace__' }; // Variants of form elements types @@ -15,12 +15,12 @@ export type FormElementGroup = { __group__: '__group__' } export type FormElementArray = { __array__: '__array__' } export type FormElementType = FormElementControl | FormElementGroup | FormElementArray | Replace -// Remove optionals and save object structure +// Remove optionals and save model structure type OnlyKeys = { [key in keyof T]-?: any } -// Traverse every key in object and transform it to form element recursively +// Traverse every key in model and transform it to form element recursively type FormModelKeyofTraverse< TModel extends Record, TAnnotations extends (OnlyKeys | FormElementType), @@ -32,7 +32,7 @@ type FormModelKeyofTraverse< > } -// Infer type of current object as form element type recursively +// Infer type of current model as form element type recursively type FormModelInnerTraverse< TModel, TAnnotations, @@ -48,7 +48,7 @@ type FormModelInnerTraverse< // FormArray annotation // // If we have array in annotation - // and current record is array + // and current model is array // then infer FormArray type recursively : TAnnotations extends FormElementArray ? TModel extends Array @@ -58,7 +58,7 @@ type FormModelInnerTraverse< // FormGroup annotation // // If we have group in annotation - // and current object has keys + // and current model has keys // then infer FormGroup type recursively : TAnnotations extends FormElementGroup ? TModel extends Record @@ -82,7 +82,7 @@ type FormModelInnerTraverse< // FormArray type annotation // // If we have array type in annotation - // and current object is array + // and current model is array // then infer FormArray type recursively : TAnnotations extends Array ? TModel extends Array @@ -91,12 +91,13 @@ type FormModelInnerTraverse< // FormGroup type annotation // - // If we have Object type in annotation - // and current object is Object + // If we have Record type in annotation + // and current model is Record // then infer FormGroup type recursively : TAnnotations extends Record ? TModel extends Record ? FormGroup> : never + // Behaviour by default : FormModelInnerTraverse \ No newline at end of file