-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesSuggestionAn idea for TypeScriptAn idea for TypeScript
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?
jcalz, fan-tom, wkronemeijer, agentcooper, b-zurg and 16 more
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesSuggestionAn idea for TypeScriptAn idea for TypeScript