gleam-lang/gleam

Invalid TypeScript Declarations for property named `constructor` and other javascript keywords

Fermée

#5 613 ouverte le 16 avr. 2026

 (1 commentaire) (0 réaction) (0 personne assignée)Rust (960 forks)batch import
good first issuehelp wantedhigh priority

Métriques du dépôt

Stars
 (21 417 étoiles)
Métriques de merge PR
 (Merge moyen 10j 19h) (69 PRs mergées en 30 j)

Description

Given this gleam code:

pub type Box {
  Box(constructor: Int)
}

And this gleam.toml:

name = "app"
version = "1.0.0"

target = "javascript"

[dependencies]
gleam_stdlib = ">= 0.44.0 and < 2.0.0"

[dev_dependencies]
gleeunit = ">= 1.0.0 and < 2.0.0"

[javascript]
typescript_declarations = true

The generated typescript declarations are invalid with the following error:

Similarly when you use other property names such as prototype or then, the generated typescript declarations are valid, however do not match the generated JavaScript classes.

For example:

pub type Box {
  Box(prototype: Int)
}
export class Box extends $CustomType {
  constructor(prototype) {
    super();
    this.prototype$ = prototype;
  }
}
export class Box extends _.CustomType {
  /** @deprecated */
  constructor(prototype: number);
  /** @deprecated */
  prototype: number;
}

Here the typescript autocompletion would suggest box.prototype even though it should be box.prototype$.

Maybe this is not important, because they are deprecated, but wanted to bring it up anyways.

This is on gleam 1.15.4

Guide contributeur