⭐️ A friendly language for building type-safe, scalable systems!
288

Configure Feed

Select the types of activity you want to include in your feed.

test: add integration test for TypeScript declarations

authored by

nkxxll and committed by
Louis Pilfold
(Jun 17, 2026, 6:46 PM +0100) b4c7e5d8 f291b48e

+114 -1
+4
.github/workflows/ci.yaml
··· 490 490 run: make 491 491 working-directory: ./test/javascript_prelude 492 492 493 + - name: Test generated TypeScript declarations 494 + run: make test 495 + working-directory: ./test/typescript_declarations 496 + 493 497 - name: Test export of hex tarball 494 498 run: make test 495 499 working-directory: ./test/hextarball
+5
Makefile
··· 24 24 cd test/project_javascript && cargo run clean && cargo run check && cargo run test 25 25 cd test/project_deno && cargo run clean && cargo run check && cargo run test 26 26 cd test/hextarball && make test 27 + cd test/typescript_declarations && make test 27 28 cd test/running_modules && make test 28 29 cd test/subdir_ffi && make 29 30 ··· 58 59 .PHONY: export-hex-tarball-test 59 60 export-hex-tarball-test: ## Run `gleam export hex-tarball` and verify it is created 60 61 cd test/hextarball && make test 62 + 63 + .PHONY: typescript-declarations-test 64 + typescript-declarations-test: ## Check that generated TypeScript declaration compile 65 + cd test/typescript_declarations && make test 61 66 62 67 .PHONY: benchmark 63 68 benchmark: ## Run the benchmarks
+1 -1
compiler-core/src/javascript/decision.rs
··· 816 816 match check { 817 817 // On JavaScript, a single "character" is one that can be represented as 818 818 // a single UTF-16 codepoint. 819 - RuntimeCheck::StringPrefix { prefix, rest } if utf16_no_escape_len(prefix) == 1 => { 819 + RuntimeCheck::StringPrefix { prefix, .. } if utf16_no_escape_len(prefix) == 1 => { 820 820 convert_string_escape_chars(prefix) 821 821 .chars() 822 822 .next()
+4
test/typescript_declarations/.gitignore
··· 1 + *.beam 2 + *.ez 3 + /build 4 + erl_crash.dump
+8
test/typescript_declarations/Makefile
··· 1 + .PHONY: clean 2 + clean: 3 + rm -rf build 4 + 5 + .PHONY: test 6 + test: 7 + cargo run --quiet -- build 8 + bunx tsc ./main.ts --strict --noEmit --skipLibCheck false --lib es2020,dom
+3
test/typescript_declarations/README.md
··· 1 + # typescript_declarations 2 + 3 + Check that generated TypeScript declarations are correct. It uses `tsc` via `bunx`.
+9
test/typescript_declarations/gleam.toml
··· 1 + name = "typescript_declarations" 2 + version = "1.0.0" 3 + target = "javascript" 4 + 5 + [javascript] 6 + typescript_declarations = true 7 + 8 + [dependencies] 9 + gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+18
test/typescript_declarations/main.ts
··· 1 + import type { Option$ } from "./build/dev/javascript/gleam_stdlib/gleam/option.d.mts"; 2 + import type { List } from "./build/dev/javascript/typescript_declarations/gleam.d.mts"; 3 + import * as gleam from "./build/dev/javascript/typescript_declarations/typescript_declarations.mjs"; 4 + 5 + gleam.const_int satisfies number 6 + gleam.const_int_alias satisfies number 7 + gleam.const_int_list satisfies List<number> 8 + gleam.const_string_list satisfies List<string> 9 + gleam.const_tuple satisfies [string, number] 10 + gleam.either_int satisfies gleam.Either$<number, number> 11 + gleam.function_int_int_returns_int_alias satisfies (a: number, b: number) => number 12 + gleam.function_closure_returns_fn_int_which_returns_int_alias satisfies () => (a: number) => number 13 + 14 + type GenericFn<T = any> = (a: T, fn: (a: T) => T) => T; 15 + gleam.function_generic_fn_generic_which_returns_generic_returns_generic satisfies GenericFn 16 + 17 + gleam.function_int_int_returns_int satisfies (a: number, b: number) => number 18 + gleam.function_option satisfies () => Option$<number>
+9
test/typescript_declarations/manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "gleam_stdlib", version = "0.62.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "0080706D3A5A9A36C40C68481D1D231D243AF602E6D2A2BE67BA8F8F4DFF45EC" }, 6 + ] 7 + 8 + [requirements] 9 + gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+53
test/typescript_declarations/src/typescript_declarations.gleam
··· 1 + import gleam/option.{type Option} 2 + 3 + /// Alias to Int 4 + pub type IntAlias = 5 + Int 6 + 7 + /// Int constant 8 + pub const const_int: Int = 0 9 + 10 + /// Constant with type of Int alias 11 + pub const const_int_alias: IntAlias = 0 12 + 13 + /// String list constant 14 + pub const const_string_list: List(String) = ["hello", "world"] 15 + 16 + /// Int list constant 17 + pub const const_int_list: List(Int) = [0, 1, 2] 18 + 19 + /// Tuple constant 20 + pub const const_tuple = #("hello", 0) 21 + 22 + /// Add two numbers 23 + pub fn function_int_int_returns_int(first a: Int, second b: Int) -> Int { 24 + a + b 25 + } 26 + 27 + /// Alias to add function 28 + pub const function_int_int_returns_int_alias = function_int_int_returns_int 29 + 30 + /// Return function that will add one to given number 31 + pub fn function_closure_returns_fn_int_which_returns_int_alias() -> fn(Int) -> 32 + IntAlias { 33 + let func = function_int_int_returns_int_alias(1, _) 34 + func 35 + } 36 + 37 + pub fn function_generic_fn_generic_which_returns_generic_returns_generic( 38 + val: a, 39 + function: fn(a) -> a, 40 + ) -> a { 41 + function(function(val)) 42 + } 43 + 44 + pub type Either(a, b) { 45 + Left(a) 46 + Right(b) 47 + } 48 + 49 + pub const either_int: Either(Int, Int) = Left(2) 50 + 51 + pub fn function_option() -> Option(Int) { 52 + option.Some(0) 53 + }