Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions compiler/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
13 changes: 13 additions & 0 deletions tests/gentype_tests/stdlib-no-shims/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SHELL = /bin/bash

test:
yarn build
yarn typecheck

clean:
yarn clean

.DEFAULT_GOAL := test

.PHONY: clean test

15 changes: 15 additions & 0 deletions tests/gentype_tests/stdlib-no-shims/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions tests/gentype_tests/stdlib-no-shims/rescript.json
Original file line number Diff line number Diff line change
@@ -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"
}

118 changes: 118 additions & 0 deletions tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.gen.tsx
Original file line number Diff line number Diff line change
@@ -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<string>) => Promise<string> = StdlibNoShimsJS.idPromise as any;

export const idDict: (x:{[id: string]: number}) => {[id: string]: number} = StdlibNoShimsJS.idDict as any;

export const idMap: (x:Map<string,number>) => Map<string,number> = StdlibNoShimsJS.idMap as any;

export const idWeakMap: (x:WeakMap<number[],number>) => WeakMap<number[],number> = StdlibNoShimsJS.idWeakMap as any;

export const idSet: (x:Set<string>) => Set<string> = StdlibNoShimsJS.idSet as any;

export const idWeakSet: (x:WeakSet<number[]>) => WeakSet<number[]> = 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<number>) => Iterator<number> = StdlibNoShimsJS.idIterator as any;

export const idAsyncIterator: (x:AsyncIterator<number>) => AsyncIterator<number> = 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;
115 changes: 115 additions & 0 deletions tests/gentype_tests/stdlib-no-shims/src/StdlibNoShims.res
Original file line number Diff line number Diff line change
@@ -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<string>) => x

@genType
let idDict = (x: Dict.t<int>) => x

@genType
let idMap = (x: Map.t<string, int>) => x

@genType
let idWeakMap = (x: WeakMap.t<array<int>, int>) => x

@genType
let idSet = (x: Set.t<string>) => x

@genType
let idWeakSet = (x: WeakSet.t<array<int>>) => x

@genType
let idArray = (x: array<int>) => x

@genType
let idUndefined = (x: undefined<int>) => x

@genType
let idNull = (x: Null.t<int>) => x

@genType
let idNullable = (x: Nullable.t<int>) => x

@genType
let idOption = (x: option<string>) => x

@genType
let idJSON = (x: JSON.t) => x

@genType
let idResult = (x: Result.t<int, string>) => x

@genType
let idResultAlias = (x: result<int, string>) => x

@genType
let idRef = (x: ref<int>) => 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<int>) => x
@genType let idAsyncIterator = (x: AsyncIterator.t<int>) => 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
Loading
Loading