Skip to content

Commit b8594ac

Browse files
GearsDatapackslpil
authored andcommitted
Generate TypeScript declarations for new JavaScript API
1 parent ce684b5 commit b8594ac

9 files changed

+299
-7
lines changed

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__shadowed_bools_and_nil_typescript.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ pub fn go(x, y) {
1616
import type * as _ from "../gleam.d.mts";
1717

1818
export class True extends _.CustomType {}
19+
export function True$True(): True$;
20+
export function True$isTrue(value: True$): boolean;
1921

2022
export class False extends _.CustomType {}
23+
export function True$False(): True$;
24+
export function True$isFalse(value: True$): boolean;
2125

2226
export class Nil extends _.CustomType {}
27+
export function True$Nil(): True$;
28+
export function True$isNil(value: True$): boolean;
2329

2430
export type True$ = True | False | Nil;
2531

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__const_with_fields_typescript.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export class Mine extends _.CustomType {
2121
a: number;
2222
b: number;
2323
}
24+
export function Mine$Mine(a: number, b: number): Mine$;
25+
export function Mine$isMine(value: Mine$): boolean;
26+
export function Mine$Mine$0(value: Mine$): number;
27+
export function Mine$Mine$a(value: Mine$): number;
28+
export function Mine$Mine$1(value: Mine$): number;
29+
export function Mine$Mine$b(value: Mine$): number;
2430

2531
export type Mine$ = Mine;
2632

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__long_name_variant_mixed_labels_typescript.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ export class TypeWithALongNameAndSeveralArguments extends _.CustomType {
2929
a: string;
3030
b: string;
3131
}
32+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments(
33+
$0: string,
34+
$1: string,
35+
$2: string,
36+
a: string,
37+
b: string,
38+
): TypeWithALongNameAndSeveralArguments$;
39+
export function TypeWithALongNameAndSeveralArguments$isTypeWithALongNameAndSeveralArguments(
40+
value: TypeWithALongNameAndSeveralArguments$,
41+
): boolean;
42+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$0(value: TypeWithALongNameAndSeveralArguments$): string;
43+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$1(
44+
value: TypeWithALongNameAndSeveralArguments$,
45+
): string;
46+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$2(value: TypeWithALongNameAndSeveralArguments$): string;
47+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$3(
48+
value: TypeWithALongNameAndSeveralArguments$,
49+
): string;
50+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$a(value: TypeWithALongNameAndSeveralArguments$): string;
51+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$4(
52+
value: TypeWithALongNameAndSeveralArguments$,
53+
): string;
54+
export function TypeWithALongNameAndSeveralArguments$TypeWithALongNameAndSeveralArguments$b(value: TypeWithALongNameAndSeveralArguments$): string;
3255

3356
export type TypeWithALongNameAndSeveralArguments$ = TypeWithALongNameAndSeveralArguments;
3457

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unapplied_record_constructors_typescript.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class Cat extends _.CustomType {
1818

1919
name: string;
2020
}
21+
export function Cat$Cat(name: string): Cat$;
22+
export function Cat$isCat(value: Cat$): boolean;
23+
export function Cat$Cat$0(value: Cat$): string;
24+
export function Cat$Cat$name(value: Cat$): string;
2125

2226
export type Cat$ = Cat;
2327

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__custom_types__unnamed_fields_typescript.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class Ip extends _.CustomType {
2020

2121
0: string;
2222
}
23+
export function Ip$Ip($0: string): Ip$;
24+
export function Ip$isIp(value: Ip$): boolean;
25+
export function Ip$Ip$0(value: Ip$): string;
2326

2427
export type Ip$ = Ip;
2528

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__generics__record_generics_typescript.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,23 @@ export class Cat<I> extends _.CustomType {
2121

2222
type_: I;
2323
}
24+
export function Animal$Cat<I>(type_: I): Animal$<I>;
25+
export function Animal$isCat<I>(value: Animal$<I>): boolean;
26+
export function Animal$Cat$0<I>(value: Animal$<I>): I;
27+
export function Animal$Cat$type_<I>(value: Animal$<I>): I;
2428

2529
export class Dog<I> extends _.CustomType {
2630
constructor(type_: I);
2731

2832
type_: I;
2933
}
34+
export function Animal$Dog<I>(type_: I): Animal$<I>;
35+
export function Animal$isDog<I>(value: Animal$<I>): boolean;
36+
export function Animal$Dog$0<I>(value: Animal$<I>): I;
37+
export function Animal$Dog$type_<I>(value: Animal$<I>): I;
3038

3139
export type Animal$<I> = Cat<I> | Dog<I>;
3240

41+
export function Animal$type_<I>(value: Animal$<I>): I;
42+
3343
export function main(): Animal$<number>;

0 commit comments

Comments
 (0)