import { If } from "../../Core/TypeConditionals"; import { Complete, NotUndefined } from "../../Core/TypeModifiers"; import ModelTraits, { IsValidSimpleTraitType } from "../../Traits/ModelTraits"; import Model from "./Model"; type SingleTrait = If< IsValidSimpleTraitType>, TTrait, TTrait extends ModelTraits ? Model : never >; type ArrayTrait<_TTrait, TElement> = ReadonlyArray>; /** * Transforms a {@link ModelTraits} class into a type representative of the traits properties exposed on * a {@link Model} class. All properties of the new type: * * * Are read-only. * * Do not allow undefined if the trait property itself does not allow undefined (i.e. it's not optional). * * Nested traits classes follow the rules above. */ type ModelPropertiesFromTraits = ModelPropertiesFromCompleteTraits>; type ModelPropertiesFromCompleteTraits = { readonly [P in keyof TDefinition]: NotUndefined extends Array< infer TElement > ? ArrayTrait, TElement> : SingleTrait; }; export default ModelPropertiesFromTraits;