Is there a better way to assign constructor parameter in Typescript? I have a class with a various set of optional parameters when instantiated.
I would like to be sure that the user input ONLY the available parameters option, and also add a default value if nothing is passed.

I come with this

export enum HexagoneType {
  POINTY,
  FLAT
}

export interface HexagoneOptions {
  center?: Vector2;
  size?: number;
  color?: string;
  type?: HexagoneType;
}

export default class Hexagone {
  ctx: CanvasRenderingContext2D;
  center: Vector2;
  size: number;
  color: string;
  type: HexagoneType;

  constructor(ctx: CanvasRenderingContext2D, options?: HexagoneOptions) {
    this.ctx = ctx;
    this.center = (options &amp;&amp; options.center) ? options.center : new Vector2();
    this.size = (options &amp;&amp; options.size) ? options.size : 100;
    this.color = (options &amp;&amp; options.color) ? options.color : "red";
    this.type = (options &amp;&amp; options.type) ? options.type : HexagoneType.POINTY;
  }
}


But is there something shorter ?
This is typical example of service locator anti pattern that should be refactored to builder pattern.

export class Hexagone {
  constructor(
    private ctx: CanvasRenderingContext2D,
    private center: Vector2,
    private size: number,
    private color: string,
    private type: HexagoneType
  ) {}
}

export class HexagoneBuilder {
  public center?: Vector2;
  public size?: number;
  public color?: string;
  public type?: HexagoneType;

  constructor(private ctx: CanvasRenderingContext2D) {}

  create() {
    return new Hexagone(
      this.ctx,
      this.center ?: new Vector2(),
      this.size ?: 100,
      this.color ?: "red",
      this.type ?: HexagonType.POINTY
    )
  }
}


Sorry if i made some syntax errors, I dont work with ts on daily basis, but you should get the idea...