Skip to content

Consider using classes rather than types with factory functions #1

@rlivings39

Description

@rlivings39

Writing

export type UnaryMinus = { kind: "unary-minus"; expr: Expr; op: "-" };
export function UnaryMinus(expr: Expr): UnaryMinus {
  return { kind: "unary-minus", expr, op: "-" };
}

instead of

export class UnaryMinus {
  readonly kind = "unary-minus";
  readonly op = "-";
  constructor(public expr: Expr) {}
}

seems more verbose and wasteful. See if there are tradeoffs and consider switching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    typescript-idiomsImprovements in the way I use TypeScript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions