microsoft / microsoft/TypeScript
Change property modifier in mapped type based on condition
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the mapped-type and conditional-type example in the issue, especially the desired required id property and optional name properties. Investigate how TypeScript represents mapped property modifiers and conditional types, then determine the feature scope and how the example would demonstrate completion. No specific source file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100