import type {Simplify} from './simplify'; type SetFieldTypeOptions = { /** Preserve optional and readonly modifiers for properties being updated. NOTE: Property modifiers will always be preserved for properties that are not being updated. @default true */ preservePropertyModifiers?: boolean; }; /** Create a type that changes the type of the given keys. Use-cases: - Creating variations of a base model. - Fixing incorrect external types. @see `Merge` if you need to change multiple properties to different types. @example ``` import type {SetFieldType} from 'type-fest'; type MyModel = { readonly id: number; readonly createdAt: Date; updatedAt?: Date; }; type MyModelApi = SetFieldType; // { // readonly id: number; // readonly createdAt: string; // updatedAt?: string; // } // `preservePropertyModifiers` option can be set to `false` if you want to remove property modifiers for properties being updated type MyModelApi = SetFieldType; // { // readonly id: number; // createdAt: string; // no longer readonly // updatedAt: string; // no longer optional // } ``` @category Object */ export type SetFieldType = Simplify<{ [P in keyof BaseType]: P extends Keys ? NewType : BaseType[P]; } & ( // `Record` is used to remove property modifiers Options['preservePropertyModifiers'] extends false ? Record : unknown )>;