I would like to do something like this:
interface IPoint {
x : number;
y : number;
z? : number;
}
const diag : IPoint = IPoint.x(1)
This handles the type:
interface IPoint {
x: number;
y: number;
z?: number;
}
type IBuilder = {
[k in keyof T]: (arg: T[k]) => IBuilder
} & { build(): T }
let builder = {} as IBuilder
const diag = builder.x(1).y(2).z(undefined).build()
But I don't know how will you create the actual Builder thou. :)
You can play around with it at the playground
EDIT: Vincent Peng has created a builder-pattern npm package our of this (as mentioned in the comment). Go and give it some love!