Open
Description
As I know there is no way to change property modifier of mapped types based on conditional types. Here is my use case:
export class MakeItRequired<T extends ModelValue<any>> {
target: "MakeItRequired" = "MakeItRequired"
constructor(public option: T) {
}
}
export type ModelValue<T> =
T extends StringConstructor ? string :
T extends NumberConstructor ? number :
T extends BooleanConstructor ? boolean :
unknown
export type ModelFromSchema<T> = {
[P in keyof T]?:
T[P] extends MakeItRequired<infer U> ? ModelValue<U> :
ModelValue<T[P]>
}
export const schema = {
id: new MakeItRequired(Number),
firstName: String,
lastName: String
}
export const type: ModelFromSchema<typeof schema> = {}
My goal is to have id
non optional, while having others optional.
Additional screenshoot from vscode:
Can we have this feature?