From 2a6e92e698a32c59078cd552330e673dcbc080e0 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 4 Sep 2025 21:43:27 +0200 Subject: [PATCH 1/5] extend gentype shims --- Makefile | 2 + .../gentype/TranslateTypeExprFromTypes.ml | 42 +++ tests/gentype_tests/stdlib-no-shims/Makefile | 13 + .../stdlib-no-shims/package.json | 15 + .../stdlib-no-shims/rescript.json | 19 ++ .../stdlib-no-shims/src/StdlibNoShims.gen.tsx | 118 ++++++++ .../stdlib-no-shims/src/StdlibNoShims.res | 115 ++++++++ .../stdlib-no-shims/src/StdlibNoShims.res.js | 266 ++++++++++++++++++ .../stdlib-no-shims/src/index.ts | 112 ++++++++ .../stdlib-no-shims/tsconfig.json | 15 + yarn.lock | 9 + 11 files changed, 726 insertions(+) create mode 100644 tests/gentype_tests/stdlib-no-shims/Makefile create mode 100644 tests/gentype_tests/stdlib-no-shims/package.json create mode 100644 tests/gentype_tests/stdlib-no-shims/rescript.json create mode 100644 tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.gen.tsx create mode 100644 tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res create mode 100644 tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res.js create mode 100644 tests/gentype_tests/stdlib-no-shims/src/index.ts create mode 100644 tests/gentype_tests/stdlib-no-shims/tsconfig.json diff --git a/Makefile b/Makefile index 9f484640c7..56b13f22c1 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ test-syntax-roundtrip: test-gentype: make -C tests/gentype_tests/typescript-react-example clean test + make -C tests/gentype_tests/stdlib-no-shims clean test test-rewatch: ./rewatch/tests/suite-ci.sh @@ -80,6 +81,7 @@ checkformat: clean-gentype: make -C tests/gentype_tests/typescript-react-example clean + make -C tests/gentype_tests/stdlib-no-shims clean clean-rewatch: cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch diff --git a/compiler/gentype/TranslateTypeExprFromTypes.ml b/compiler/gentype/TranslateTypeExprFromTypes.ml index b6cdb8faff..5e6024495a 100644 --- a/compiler/gentype/TranslateTypeExprFromTypes.ml +++ b/compiler/gentype/TranslateTypeExprFromTypes.ml @@ -118,6 +118,48 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env = } | (["Js"; "Re"; "t"] | ["RegExp"; "t"] | ["Stdlib"; "RegExp"; "t"]), [] -> {dependencies = []; type_ = regexp_t} + | ["Stdlib"; "ArrayBuffer"; "t"], [] -> + {dependencies = []; type_ = ident "ArrayBuffer"} + | ["Stdlib"; "DataView"; "t"], [] -> + {dependencies = []; type_ = ident "DataView"} + | ["Stdlib"; "Int8Array"; "t"], [] -> + {dependencies = []; type_ = ident "Int8Array"} + | ["Stdlib"; "Uint8Array"; "t"], [] -> + {dependencies = []; type_ = ident "Uint8Array"} + | ["Stdlib"; "Uint8ClampedArray"; "t"], [] -> + {dependencies = []; type_ = ident "Uint8ClampedArray"} + | ["Stdlib"; "Int16Array"; "t"], [] -> + {dependencies = []; type_ = ident "Int16Array"} + | ["Stdlib"; "Uint16Array"; "t"], [] -> + {dependencies = []; type_ = ident "Uint16Array"} + | ["Stdlib"; "Int32Array"; "t"], [] -> + {dependencies = []; type_ = ident "Int32Array"} + | ["Stdlib"; "Uint32Array"; "t"], [] -> + {dependencies = []; type_ = ident "Uint32Array"} + | ["Stdlib"; "Float32Array"; "t"], [] -> + {dependencies = []; type_ = ident "Float32Array"} + | ["Stdlib"; "Float64Array"; "t"], [] -> + {dependencies = []; type_ = ident "Float64Array"} + | ["Stdlib"; "BigInt64Array"; "t"], [] -> + {dependencies = []; type_ = ident "BigInt64Array"} + | ["Stdlib"; "BigUint64Array"; "t"], [] -> + {dependencies = []; type_ = ident "BigUint64Array"} + | ["Stdlib"; "Symbol"; "t"], [] -> {dependencies = []; type_ = ident "symbol"} + | ["Stdlib"; "Intl"; intl_module; "t"], [] -> + {dependencies = []; type_ = ident ("Intl." ^ intl_module)} + | (["Stdlib"; "Error"; "t"] | ["Stdlib"; "JsError"; "t"]), [] -> + {dependencies = []; type_ = ident "Error"} + | ["Stdlib"; "Iterator"; "t"], [param_translation] -> + { + dependencies = param_translation.dependencies; + type_ = ident ~type_args:[param_translation.type_] "Iterator"; + } + | ["Stdlib"; "AsyncIterator"; "t"], [param_translation] -> + { + dependencies = param_translation.dependencies; + type_ = ident ~type_args:[param_translation.type_] "AsyncIterator"; + } + | ["Stdlib"; "Ordering"; "t"], [] -> {dependencies = []; type_ = number_t} | ["unit"], [] -> {dependencies = []; type_ = unit_t} | (["array"] | ["Js"; ("Array" | "Array2"); "t"]), [param_translation] -> {param_translation with type_ = Array (param_translation.type_, Mutable)} diff --git a/tests/gentype_tests/stdlib-no-shims/Makefile b/tests/gentype_tests/stdlib-no-shims/Makefile new file mode 100644 index 0000000000..b225f0ada3 --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/Makefile @@ -0,0 +1,13 @@ +SHELL = /bin/bash + +test: + yarn build + yarn typecheck + +clean: + yarn clean + +.DEFAULT_GOAL := test + +.PHONY: clean test + diff --git a/tests/gentype_tests/stdlib-no-shims/package.json b/tests/gentype_tests/stdlib-no-shims/package.json new file mode 100644 index 0000000000..2429b5c8bc --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/package.json @@ -0,0 +1,15 @@ +{ + "name": "@tests/gentype-stdlib-no-shims", + "private": true, + "scripts": { + "build": "rescript legacy build", + "clean": "rescript clean", + "typecheck": "tsc" + }, + "dependencies": { + "rescript": "workspace:^" + }, + "devDependencies": { + "typescript": "5.8.2" + } +} diff --git a/tests/gentype_tests/stdlib-no-shims/rescript.json b/tests/gentype_tests/stdlib-no-shims/rescript.json new file mode 100644 index 0000000000..b96188e035 --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/rescript.json @@ -0,0 +1,19 @@ +{ + "gentypeconfig": { + "language": "typescript", + "module": "esmodule", + "importPath": "relative", + "debug": { "all": false }, + "exportInterfaces": false + }, + "name": "@tests/gentype-stdlib-no-shims", + "sources": [ + { "dir": "src", "subdirs": true } + ], + "package-specs": { + "module": "esmodule", + "in-source": true + }, + "suffix": ".res.js" +} + diff --git a/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.gen.tsx b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.gen.tsx new file mode 100644 index 0000000000..8f46ce8d85 --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.gen.tsx @@ -0,0 +1,118 @@ +/* TypeScript file generated from StdlibNoShims.res by genType. */ + +/* eslint-disable */ +/* tslint:disable */ + +import * as StdlibNoShimsJS from './StdlibNoShims.res.js'; + +export const idInt: (x:number) => number = StdlibNoShimsJS.idInt as any; + +export const idFloat: (x:number) => number = StdlibNoShimsJS.idFloat as any; + +export const idBool: (x:boolean) => boolean = StdlibNoShimsJS.idBool as any; + +export const idString: (x:string) => string = StdlibNoShimsJS.idString as any; + +export const idBigInt: (x:bigint) => bigint = StdlibNoShimsJS.idBigInt as any; + +export const idDate: (x:Date) => Date = StdlibNoShimsJS.idDate as any; + +export const idRegExp: (x:RegExp) => RegExp = StdlibNoShimsJS.idRegExp as any; + +export const idPromise: (x:Promise) => Promise = StdlibNoShimsJS.idPromise as any; + +export const idDict: (x:{[id: string]: number}) => {[id: string]: number} = StdlibNoShimsJS.idDict as any; + +export const idMap: (x:Map) => Map = StdlibNoShimsJS.idMap as any; + +export const idWeakMap: (x:WeakMap) => WeakMap = StdlibNoShimsJS.idWeakMap as any; + +export const idSet: (x:Set) => Set = StdlibNoShimsJS.idSet as any; + +export const idWeakSet: (x:WeakSet) => WeakSet = StdlibNoShimsJS.idWeakSet as any; + +export const idArray: (x:number[]) => number[] = StdlibNoShimsJS.idArray as any; + +export const idUndefined: (x:(undefined | number)) => (undefined | number) = StdlibNoShimsJS.idUndefined as any; + +export const idNull: (x:(null | number)) => (null | number) = StdlibNoShimsJS.idNull as any; + +export const idNullable: (x:(null | undefined | number)) => (null | undefined | number) = StdlibNoShimsJS.idNullable as any; + +export const idOption: (x:(undefined | string)) => (undefined | string) = StdlibNoShimsJS.idOption as any; + +export const idJSON: (x:unknown) => unknown = StdlibNoShimsJS.idJSON as any; + +export const idResult: (x: + { TAG: "Ok"; _0: number } + | { TAG: "Error"; _0: string }) => + { TAG: "Ok"; _0: number } + | { TAG: "Error"; _0: string } = StdlibNoShimsJS.idResult as any; + +export const idResultAlias: (x: + { TAG: "Ok"; _0: number } + | { TAG: "Error"; _0: string }) => + { TAG: "Ok"; _0: number } + | { TAG: "Error"; _0: string } = StdlibNoShimsJS.idResultAlias as any; + +export const idRef: (x:{ contents: number }) => { contents: number } = StdlibNoShimsJS.idRef as any; + +export const returnsUnit: () => void = StdlibNoShimsJS.returnsUnit as any; + +export const idTuple: (x:[number, string, number]) => [number, string, number] = StdlibNoShimsJS.idTuple as any; + +export const idArrayBuffer: (x:ArrayBuffer) => ArrayBuffer = StdlibNoShimsJS.idArrayBuffer as any; + +export const idDataView: (x:DataView) => DataView = StdlibNoShimsJS.idDataView as any; + +export const idInt8Array: (x:Int8Array) => Int8Array = StdlibNoShimsJS.idInt8Array as any; + +export const idUint8Array: (x:Uint8Array) => Uint8Array = StdlibNoShimsJS.idUint8Array as any; + +export const idUint8ClampedArray: (x:Uint8ClampedArray) => Uint8ClampedArray = StdlibNoShimsJS.idUint8ClampedArray as any; + +export const idInt16Array: (x:Int16Array) => Int16Array = StdlibNoShimsJS.idInt16Array as any; + +export const idUint16Array: (x:Uint16Array) => Uint16Array = StdlibNoShimsJS.idUint16Array as any; + +export const idInt32Array: (x:Int32Array) => Int32Array = StdlibNoShimsJS.idInt32Array as any; + +export const idUint32Array: (x:Uint32Array) => Uint32Array = StdlibNoShimsJS.idUint32Array as any; + +export const idFloat32Array: (x:Float32Array) => Float32Array = StdlibNoShimsJS.idFloat32Array as any; + +export const idFloat64Array: (x:Float64Array) => Float64Array = StdlibNoShimsJS.idFloat64Array as any; + +export const idBigInt64Array: (x:BigInt64Array) => BigInt64Array = StdlibNoShimsJS.idBigInt64Array as any; + +export const idBigUint64Array: (x:BigUint64Array) => BigUint64Array = StdlibNoShimsJS.idBigUint64Array as any; + +export const idSymbol: (x:symbol) => symbol = StdlibNoShimsJS.idSymbol as any; + +export const idIterator: (x:Iterator) => Iterator = StdlibNoShimsJS.idIterator as any; + +export const idAsyncIterator: (x:AsyncIterator) => AsyncIterator = StdlibNoShimsJS.idAsyncIterator as any; + +export const idOrdering: (x:number) => number = StdlibNoShimsJS.idOrdering as any; + +export const idIntlCollator: (x:Intl.Collator) => Intl.Collator = StdlibNoShimsJS.idIntlCollator as any; + +export const idIntlDateTimeFormat: (x:Intl.DateTimeFormat) => Intl.DateTimeFormat = StdlibNoShimsJS.idIntlDateTimeFormat as any; + +export const idIntlListFormat: (x:Intl.ListFormat) => Intl.ListFormat = StdlibNoShimsJS.idIntlListFormat as any; + +export const idIntlLocale: (x:Intl.Locale) => Intl.Locale = StdlibNoShimsJS.idIntlLocale as any; + +export const idIntlNumberFormat: (x:Intl.NumberFormat) => Intl.NumberFormat = StdlibNoShimsJS.idIntlNumberFormat as any; + +export const idIntlPluralRules: (x:Intl.PluralRules) => Intl.PluralRules = StdlibNoShimsJS.idIntlPluralRules as any; + +export const idIntlRelativeTimeFormat: (x:Intl.RelativeTimeFormat) => Intl.RelativeTimeFormat = StdlibNoShimsJS.idIntlRelativeTimeFormat as any; + +export const idIntlSegmenter: (x:Intl.Segmenter) => Intl.Segmenter = StdlibNoShimsJS.idIntlSegmenter as any; + +export const idIntlSegments: (x:Intl.Segments) => Intl.Segments = StdlibNoShimsJS.idIntlSegments as any; + +export const idJsError: (x:Error) => Error = StdlibNoShimsJS.idJsError as any; + +export const idObj: (x:{}) => {} = StdlibNoShimsJS.idObj as any; diff --git a/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res new file mode 100644 index 0000000000..413caa0cbe --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res @@ -0,0 +1,115 @@ +// Verify Stdlib.* types map without TS shims + +@genType +let idInt = (x: int) => x + +@genType +let idFloat = (x: float) => x + +@genType +let idBool = (x: bool) => x + +@genType +let idString = (x: String.t) => x + +@genType +let idBigInt = (x: bigint) => x + +@genType +let idDate = (x: Date.t) => x + +@genType +let idRegExp = (x: RegExp.t) => x + +@genType +let idPromise = (x: Promise.t) => x + +@genType +let idDict = (x: Dict.t) => x + +@genType +let idMap = (x: Map.t) => x + +@genType +let idWeakMap = (x: WeakMap.t, int>) => x + +@genType +let idSet = (x: Set.t) => x + +@genType +let idWeakSet = (x: WeakSet.t>) => x + +@genType +let idArray = (x: array) => x + +@genType +let idUndefined = (x: undefined) => x + +@genType +let idNull = (x: Null.t) => x + +@genType +let idNullable = (x: Nullable.t) => x + +@genType +let idOption = (x: option) => x + +@genType +let idJSON = (x: JSON.t) => x + +@genType +let idResult = (x: Result.t) => x + +@genType +let idResultAlias = (x: result) => x + +@genType +let idRef = (x: ref) => x + +@genType +let returnsUnit = () : unit => () +@genType +let idTuple = (x: (int, string, float)) => x + +// Typed arrays and related JS interop types +@genType let idArrayBuffer = (x: ArrayBuffer.t) => x +@genType let idDataView = (x: DataView.t) => x + +@genType let idInt8Array = (x: Int8Array.t) => x +@genType let idUint8Array = (x: Uint8Array.t) => x +@genType let idUint8ClampedArray = (x: Uint8ClampedArray.t) => x +@genType let idInt16Array = (x: Int16Array.t) => x +@genType let idUint16Array = (x: Uint16Array.t) => x +@genType let idInt32Array = (x: Int32Array.t) => x +@genType let idUint32Array = (x: Uint32Array.t) => x +@genType let idFloat32Array = (x: Float32Array.t) => x +@genType let idFloat64Array = (x: Float64Array.t) => x +@genType let idBigInt64Array = (x: BigInt64Array.t) => x +@genType let idBigUint64Array = (x: BigUint64Array.t) => x + +// Additional stdlib types +@genType let idSymbol = (x: Symbol.t) => x + +// More Stdlib exposed types (add more as generator support grows) +@genType let idIterator = (x: Iterator.t) => x +@genType let idAsyncIterator = (x: AsyncIterator.t) => x +@genType let idOrdering = (x: Ordering.t) => x + +// Intl* types +@genType let idIntlCollator = (x: Intl.Collator.t) => x +@genType let idIntlDateTimeFormat = (x: Intl.DateTimeFormat.t) => x +@genType let idIntlListFormat = (x: Intl.ListFormat.t) => x +@genType let idIntlLocale = (x: Intl.Locale.t) => x +@genType let idIntlNumberFormat = (x: Intl.NumberFormat.t) => x +@genType let idIntlPluralRules = (x: Intl.PluralRules.t) => x +@genType let idIntlRelativeTimeFormat = (x: Intl.RelativeTimeFormat.t) => x +@genType let idIntlSegmenter = (x: Intl.Segmenter.t) => x +@genType let idIntlSegments = (x: Intl.Segments.t) => x + +// Errors +@genType let idJsError = (x: JsError.t) => x + +// Dynamic object +@genType let idObj = (x: {..}) => x + +// dummy change to trigger rebuild diff --git a/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res.js b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res.js new file mode 100644 index 0000000000..76b6e6b3e2 --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res.js @@ -0,0 +1,266 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +function idInt(x) { + return x; +} + +function idFloat(x) { + return x; +} + +function idBool(x) { + return x; +} + +function idString(x) { + return x; +} + +function idBigInt(x) { + return x; +} + +function idDate(x) { + return x; +} + +function idRegExp(x) { + return x; +} + +function idPromise(x) { + return x; +} + +function idDict(x) { + return x; +} + +function idMap(x) { + return x; +} + +function idWeakMap(x) { + return x; +} + +function idSet(x) { + return x; +} + +function idWeakSet(x) { + return x; +} + +function idArray(x) { + return x; +} + +function idUndefined(x) { + return x; +} + +function idNull(x) { + return x; +} + +function idNullable(x) { + return x; +} + +function idOption(x) { + return x; +} + +function idJSON(x) { + return x; +} + +function idResult(x) { + return x; +} + +function idResultAlias(x) { + return x; +} + +function idRef(x) { + return x; +} + +function returnsUnit() { + +} + +function idTuple(x) { + return x; +} + +function idArrayBuffer(x) { + return x; +} + +function idDataView(x) { + return x; +} + +function idInt8Array(x) { + return x; +} + +function idUint8Array(x) { + return x; +} + +function idUint8ClampedArray(x) { + return x; +} + +function idInt16Array(x) { + return x; +} + +function idUint16Array(x) { + return x; +} + +function idInt32Array(x) { + return x; +} + +function idUint32Array(x) { + return x; +} + +function idFloat32Array(x) { + return x; +} + +function idFloat64Array(x) { + return x; +} + +function idBigInt64Array(x) { + return x; +} + +function idBigUint64Array(x) { + return x; +} + +function idSymbol(x) { + return x; +} + +function idIterator(x) { + return x; +} + +function idAsyncIterator(x) { + return x; +} + +function idOrdering(x) { + return x; +} + +function idIntlCollator(x) { + return x; +} + +function idIntlDateTimeFormat(x) { + return x; +} + +function idIntlListFormat(x) { + return x; +} + +function idIntlLocale(x) { + return x; +} + +function idIntlNumberFormat(x) { + return x; +} + +function idIntlPluralRules(x) { + return x; +} + +function idIntlRelativeTimeFormat(x) { + return x; +} + +function idIntlSegmenter(x) { + return x; +} + +function idIntlSegments(x) { + return x; +} + +function idJsError(x) { + return x; +} + +function idObj(x) { + return x; +} + +export { + idInt, + idFloat, + idBool, + idString, + idBigInt, + idDate, + idRegExp, + idPromise, + idDict, + idMap, + idWeakMap, + idSet, + idWeakSet, + idArray, + idUndefined, + idNull, + idNullable, + idOption, + idJSON, + idResult, + idResultAlias, + idRef, + returnsUnit, + idTuple, + idArrayBuffer, + idDataView, + idInt8Array, + idUint8Array, + idUint8ClampedArray, + idInt16Array, + idUint16Array, + idInt32Array, + idUint32Array, + idFloat32Array, + idFloat64Array, + idBigInt64Array, + idBigUint64Array, + idSymbol, + idIterator, + idAsyncIterator, + idOrdering, + idIntlCollator, + idIntlDateTimeFormat, + idIntlListFormat, + idIntlLocale, + idIntlNumberFormat, + idIntlPluralRules, + idIntlRelativeTimeFormat, + idIntlSegmenter, + idIntlSegments, + idJsError, + idObj, +} +/* No side effect */ diff --git a/tests/gentype_tests/stdlib-no-shims/src/index.ts b/tests/gentype_tests/stdlib-no-shims/src/index.ts new file mode 100644 index 0000000000..bc4260e881 --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/src/index.ts @@ -0,0 +1,112 @@ +// Import the generated bindings to force TS to resolve types without shims +import * as S from "./StdlibNoShims.gen"; + +// primitives +const i: number = S.idInt(1); +const f: number = S.idFloat(1.5); +const b: boolean = S.idBool(true); + +// string +const s: string = S.idString("hello"); + +// bigint +const bi: bigint = S.idBigInt(1n); + +// Date +const d: Date = S.idDate(new Date()); + +// RegExp +const re: RegExp = S.idRegExp(/a/); + +// Promise +const p: Promise = S.idPromise(Promise.resolve("ok")); + +// Dict +const dict: { [id: string]: number } = S.idDict({ a: 1, b: 2 }); + +// Map / WeakMap +const m: Map = S.idMap(new Map()); +const wm: WeakMap = S.idWeakMap(new WeakMap()); + +// Set / WeakSet +const set: Set = S.idSet(new Set()); +const wset: WeakSet = S.idWeakSet(new WeakSet()); + +// undefined / null / nullable +const u: undefined | number = S.idUndefined(undefined); +const n: null | number = S.idNull(null as any); +const nu: null | undefined | number = S.idNullable(undefined); + +// option +const opt: string | undefined = S.idOption(undefined); + +// JSON +const j: unknown = S.idJSON({}); + +// Result +const ok: { TAG: "Ok"; _0: number } = { TAG: "Ok", _0: 1 }; +const err: { TAG: "Error"; _0: string } = { TAG: "Error", _0: "e" }; +const r1 = S.idResult(ok); +const r2 = S.idResult(err); + +// result alias +const r3 = S.idResultAlias(ok); +const r4 = S.idResultAlias(err); + +// array +const arr: number[] = S.idArray([1, 2, 3]); + +// ref +const refv: { contents: number } = S.idRef({ contents: 1 }); + +// unit return +const voidReturn: void = S.returnsUnit(); + +// ArrayBuffer / DataView +const ab: ArrayBuffer = S.idArrayBuffer(new ArrayBuffer(8)); +const dv: DataView = S.idDataView(new DataView(ab)); + +// Typed arrays +const i8: Int8Array = S.idInt8Array(new Int8Array()); +const u8: Uint8Array = S.idUint8Array(new Uint8Array()); +const u8c: Uint8ClampedArray = S.idUint8ClampedArray(new Uint8ClampedArray()); +const i16: Int16Array = S.idInt16Array(new Int16Array()); +const u16: Uint16Array = S.idUint16Array(new Uint16Array()); +const i32: Int32Array = S.idInt32Array(new Int32Array()); +const u32: Uint32Array = S.idUint32Array(new Uint32Array()); +const f32: Float32Array = S.idFloat32Array(new Float32Array()); +const f64: Float64Array = S.idFloat64Array(new Float64Array()); +const bi64: BigInt64Array = S.idBigInt64Array(new BigInt64Array(2)); +const bu64: BigUint64Array = S.idBigUint64Array(new BigUint64Array(2)); + +// Symbol (may not be mapped yet) +const sym: symbol = S.idSymbol(Symbol("x")); + +// Iterator / AsyncIterator / Ordering +const it: Iterator = S.idIterator([1, 2, 3].values()); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const ait: AsyncIterator = S.idAsyncIterator({} as any); +const ord: number = S.idOrdering(0); + +// Intl family +const _coll: Intl.Collator = S.idIntlCollator(new Intl.Collator()); +const _dtf: Intl.DateTimeFormat = S.idIntlDateTimeFormat(new Intl.DateTimeFormat()); +const _lf: Intl.ListFormat = S.idIntlListFormat(new Intl.ListFormat()); +const _loc: Intl.Locale = S.idIntlLocale(new (Intl as any).Locale("en-US")); +const _nf: Intl.NumberFormat = S.idIntlNumberFormat(new Intl.NumberFormat()); +const _pr: Intl.PluralRules = S.idIntlPluralRules(new Intl.PluralRules()); +const _rtf: Intl.RelativeTimeFormat = S.idIntlRelativeTimeFormat(new Intl.RelativeTimeFormat()); +const _seg: Intl.Segmenter = S.idIntlSegmenter(new (Intl as any).Segmenter()); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const _segs: Intl.Segments = S.idIntlSegments((new (Intl as any).Segmenter()).segment("hello") as any); + +// Errors (use JsError only) +const _jserr: Error = S.idJsError(new Error("x")); + +// Generic object +const _obj: {} = S.idObj({ a: 1, b: "x" }); + +// Tuple +const _tup: [number, string, number] = S.idTuple([1, "x", 1.5]); + +// No exports needed; existence and types are checked by TS. diff --git a/tests/gentype_tests/stdlib-no-shims/tsconfig.json b/tests/gentype_tests/stdlib-no-shims/tsconfig.json new file mode 100644 index 0000000000..d466b70893 --- /dev/null +++ b/tests/gentype_tests/stdlib-no-shims/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "Node", + "jsx": "preserve", + "strict": true, + "noEmit": true, + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "skipLibCheck": true, + "allowImportingTsExtensions": true, + "allowJs": true + }, + "include": ["src/**/*.ts", "src/**/*.tsx"] +} diff --git a/yarn.lock b/yarn.lock index 44840efa72..81e1630eae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -675,6 +675,15 @@ __metadata: languageName: unknown linkType: soft +"@tests/gentype-stdlib-no-shims@workspace:tests/gentype_tests/stdlib-no-shims": + version: 0.0.0-use.local + resolution: "@tests/gentype-stdlib-no-shims@workspace:tests/gentype_tests/stdlib-no-shims" + dependencies: + rescript: "workspace:^" + typescript: "npm:5.8.2" + languageName: unknown + linkType: soft + "@tests/incremental-typechecking@workspace:tests/analysis_tests/tests-incremental-typechecking": version: 0.0.0-use.local resolution: "@tests/incremental-typechecking@workspace:tests/analysis_tests/tests-incremental-typechecking" From ac1ce148e601dc6e9feae321a8fe9a8ad1f33667 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 4 Sep 2025 21:46:40 +0200 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66de9f1385..42c1ab3b08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ #### :rocket: New Feature +- Support mapping more standard library types automatically to TS types via `gentype`, without requiring shims. https://github.com/rescript-lang/rescript/pull/7842 + #### :bug: Bug fix - Show `Stdlib.TypedArray` completions for typed arrays. https://github.com/rescript-lang/rescript/pull/7827 From 2b3bf701093e93234d5e46c2d9f660f74b87dc45 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 4 Sep 2025 21:48:24 +0200 Subject: [PATCH 3/5] format --- tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res | 2 +- tests/gentype_tests/stdlib-no-shims/src/index.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res index 413caa0cbe..f37f614d7d 100644 --- a/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res +++ b/tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res @@ -67,7 +67,7 @@ let idResultAlias = (x: result) => x let idRef = (x: ref) => x @genType -let returnsUnit = () : unit => () +let returnsUnit = (): unit => () @genType let idTuple = (x: (int, string, float)) => x diff --git a/tests/gentype_tests/stdlib-no-shims/src/index.ts b/tests/gentype_tests/stdlib-no-shims/src/index.ts index bc4260e881..11bbdd1ab6 100644 --- a/tests/gentype_tests/stdlib-no-shims/src/index.ts +++ b/tests/gentype_tests/stdlib-no-shims/src/index.ts @@ -109,4 +109,3 @@ const _obj: {} = S.idObj({ a: 1, b: "x" }); // Tuple const _tup: [number, string, number] = S.idTuple([1, "x", 1.5]); -// No exports needed; existence and types are checked by TS. From c3ca19dd1a56c2ec8239b0669006e2462655fc73 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 4 Sep 2025 21:57:14 +0200 Subject: [PATCH 4/5] remove a few unecessary --- .../stdlib-no-shims/src/index.ts | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/gentype_tests/stdlib-no-shims/src/index.ts b/tests/gentype_tests/stdlib-no-shims/src/index.ts index 11bbdd1ab6..b9d7ec8710 100644 --- a/tests/gentype_tests/stdlib-no-shims/src/index.ts +++ b/tests/gentype_tests/stdlib-no-shims/src/index.ts @@ -26,7 +26,9 @@ const dict: { [id: string]: number } = S.idDict({ a: 1, b: 2 }); // Map / WeakMap const m: Map = S.idMap(new Map()); -const wm: WeakMap = S.idWeakMap(new WeakMap()); +const wm: WeakMap = S.idWeakMap( + new WeakMap() +); // Set / WeakSet const set: Set = S.idSet(new Set()); @@ -34,7 +36,7 @@ const wset: WeakSet = S.idWeakSet(new WeakSet()); // undefined / null / nullable const u: undefined | number = S.idUndefined(undefined); -const n: null | number = S.idNull(null as any); +const n: null | number = S.idNull(null); const nu: null | undefined | number = S.idNullable(undefined); // option @@ -90,15 +92,20 @@ const ord: number = S.idOrdering(0); // Intl family const _coll: Intl.Collator = S.idIntlCollator(new Intl.Collator()); -const _dtf: Intl.DateTimeFormat = S.idIntlDateTimeFormat(new Intl.DateTimeFormat()); +const _dtf: Intl.DateTimeFormat = S.idIntlDateTimeFormat( + new Intl.DateTimeFormat() +); const _lf: Intl.ListFormat = S.idIntlListFormat(new Intl.ListFormat()); -const _loc: Intl.Locale = S.idIntlLocale(new (Intl as any).Locale("en-US")); +const _loc: Intl.Locale = S.idIntlLocale(new Intl.Locale("en-US")); const _nf: Intl.NumberFormat = S.idIntlNumberFormat(new Intl.NumberFormat()); const _pr: Intl.PluralRules = S.idIntlPluralRules(new Intl.PluralRules()); -const _rtf: Intl.RelativeTimeFormat = S.idIntlRelativeTimeFormat(new Intl.RelativeTimeFormat()); -const _seg: Intl.Segmenter = S.idIntlSegmenter(new (Intl as any).Segmenter()); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const _segs: Intl.Segments = S.idIntlSegments((new (Intl as any).Segmenter()).segment("hello") as any); +const _rtf: Intl.RelativeTimeFormat = S.idIntlRelativeTimeFormat( + new Intl.RelativeTimeFormat() +); +const _seg: Intl.Segmenter = S.idIntlSegmenter(new Intl.Segmenter()); +const _segs: Intl.Segments = S.idIntlSegments( + new Intl.Segmenter().segment("hello") +); // Errors (use JsError only) const _jserr: Error = S.idJsError(new Error("x")); @@ -108,4 +115,3 @@ const _obj: {} = S.idObj({ a: 1, b: "x" }); // Tuple const _tup: [number, string, number] = S.idTuple([1, "x", 1.5]); - From 4369f1a21a479c6d77cc22f5d08074c2baeaeae6 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 4 Sep 2025 22:02:20 +0200 Subject: [PATCH 5/5] proper async iterator without any as well --- tests/gentype_tests/stdlib-no-shims/src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/gentype_tests/stdlib-no-shims/src/index.ts b/tests/gentype_tests/stdlib-no-shims/src/index.ts index b9d7ec8710..456660117e 100644 --- a/tests/gentype_tests/stdlib-no-shims/src/index.ts +++ b/tests/gentype_tests/stdlib-no-shims/src/index.ts @@ -86,8 +86,11 @@ const sym: symbol = S.idSymbol(Symbol("x")); // Iterator / AsyncIterator / Ordering const it: Iterator = S.idIterator([1, 2, 3].values()); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const ait: AsyncIterator = S.idAsyncIterator({} as any); +const ait: AsyncIterator = S.idAsyncIterator({ + next(): Promise> { + return Promise.resolve({ done: true, value: undefined }); + }, +}); const ord: number = S.idOrdering(0); // Intl family