Skip to content

[FEATURE]: TypeScript erasableSyntaxOnly #2861

@arv

Description

@arv

Node.js can now run a subset of TypeScript without any flags. The subset can be enforced using the tsconfig flag erasableSyntaxOnly. https://www.typescriptlang.org/tsconfig/#erasableSyntaxOnly

Context (Input, Language)

Input Format: any (?)
Output Language: Typescript

Description

Current Behaviour / Output

By default the typescript generator generates enums. This can be dealt with using --prefer-unions flag to quicktype.

However, the converter "classes" have this:

/**
 * @schema X
 */
export class X {
  public static fromNumber(value: number): X {
    return new X(value);
  }
  public static fromString(value: string): X {
    return new X(value);
  }
  private constructor(public readonly value: number | string) {
  }
}

Proposed Behaviour / Output

A better output would be:

/**
 * @schema X
 */
export class X {
  readonly value: number | string;
  
  public static fromNumber(value: number): X {
    return new X(value);
  }
  public static fromString(value: string): X {
    return new X(value);
  }
  
  private constructor(value: number | string) {
    this.value = value;
  }
}

Solution

Maybe add an --erasable-syntax-only and generate compatible code?

Alternatives

Only generate the types...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions