Skip to content

Add @notUndefined attribute to more Stdlib abstract types #7464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 13, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

- In type errors, recommend stdlib over Belt functions for converting between float/int/string. https://github.com/rescript-lang/rescript/pull/7453
- Remove unused type `Jsx.ref`. https://github.com/rescript-lang/rescript/pull/7459
- Add `@notUndefined` attribute to all relevant abstract types in `Stdlib`. https://github.com/rescript-lang/rescript/pull/7464

# 12.0.0-alpha.12

Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_ArrayBuffer.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

@new external make: int => t = "ArrayBuffer"
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_AsyncIterator.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'a>

type value<'a> = {
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_AsyncIterator.resi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/Java
/**
The type representing an async iterator.
*/
@notUndefined
type t<'a>

type value<'a> = {
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_DataView.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

@new external fromBuffer: Stdlib_ArrayBuffer.t => t = "DataView"
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_Collator.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type usage = [#sort | #search]
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_DateTimeFormat.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type dateStyle = [#full | #long | #medium | #short]
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_ListFormat.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type listType = [
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_Locale.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type options = {
Expand Down
3 changes: 2 additions & 1 deletion runtime/Stdlib_Intl_NumberFormat.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Grouping = Stdlib_Intl_NumberFormat_Grouping

@notUndefined
type t

/**
Expand Down Expand Up @@ -211,7 +212,7 @@ external formatBigIntRangeToParts: (t, ~start: bigint, ~end: bigint) => array<nu
external formatStringToParts: (t, string) => array<numberFormatRangePart> = "formatToParts"

/**
`ignore(numberGrouping)` ignores the provided numberGrouping and returns unit.
`ignore(numberFormat)` ignores the provided numberFormat and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
without having to store or process it further.
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_NumberFormat_Grouping.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type parsed = [#bool(bool) | #always | #auto | #min2]
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_PluralRules.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type localeType = [#cardinal | #ordinal]
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_RelativeTimeFormat.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

type numeric = [#always | #auto]
Expand Down
4 changes: 1 addition & 3 deletions runtime/Stdlib_Intl_Segmenter.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/***
Not supported in Firefox
*/
@notUndefined
type t

type granularity = [#grapheme | #word | #sentence]
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Intl_Segments.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A Segments instance is an object that represents the segments of a specific string, subject to the locale and options of its constructing Intl.Segmenter instance.
https://tc39.es/ecma402/#sec-segments-objects
*/
@notUndefined
type t

type segmentData = {
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Iterator.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'a>

type value<'a> = {
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Iterator.resi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See [`iterator protocols`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
/**
The type representing an iterator.
*/
@notUndefined
type t<'a>

/**
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_JsError.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

@get external stack: t => option<string> = "stack"
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_JsError.resi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
*/

/** Represents a JavaScript error. */
@notUndefined
type t

/**
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Map.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'k, 'v>

@new external make: unit => t<'k, 'v> = "Map"
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Map.resi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl
/**
Type representing an instance of `Map`.
*/
@notUndefined
type t<'k, 'v>

/**
Expand Down
2 changes: 1 addition & 1 deletion runtime/Stdlib_Pair.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Pair.second((1, 2))->assertEqual(2)
external second: (('a, 'b)) => 'b = "%field1"

/**
`ignore(option)` ignores the provided pair and returns unit.
`ignore(pair)` ignores the provided pair and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
without having to store or process it further.
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Set.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'a>

@new external make: unit => t<'a> = "Set"
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Set.resi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl
/**
Type representing an instance of `Set`.
*/
@notUndefined
type t<'a>

/**
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_Symbol.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t

@val external make: string => t = "Symbol"
Expand Down
3 changes: 2 additions & 1 deletion runtime/Stdlib_Symbol.resi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Compiles to a regular JavaScript Symbol.
/**
Type representing a Symbol.
*/
@notUndefined
type t

/**
Expand All @@ -28,7 +29,7 @@ external make: string => t = "Symbol"
/**
`getFor(key)`

Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found.
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found.
Otherwise a new Symbol gets created and registered with key.

## Examples
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_TypedArray.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'a>

@get_index external get: (t<'a>, int) => option<'a> = ""
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_WeakMap.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'k, 'v>

@new external make: unit => t<'k, 'v> = "WeakMap"
Expand Down
1 change: 1 addition & 0 deletions runtime/Stdlib_WeakSet.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@notUndefined
type t<'a>

@new external make: unit => t<'a> = "WeakSet"
Expand Down
3 changes: 1 addition & 2 deletions tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Primitive_option from "rescript/lib/es6/Primitive_option.js";
import * as Stdlib_Intl_NumberFormat_Grouping from "rescript/lib/es6/Stdlib_Intl_NumberFormat_Grouping.js";

console.log("---");
Expand All @@ -26,7 +25,7 @@ let roundingFormatter = new Intl.NumberFormat(undefined, {
});

let groupingFormatter1 = new Intl.NumberFormat(undefined, {
useGrouping: Primitive_option.some(true)
useGrouping: true
});

let groupingFormatter2 = new Intl.NumberFormat(undefined, {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/internal_unused_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module P1 = {
}
open! P1

let f = () => raise(A)
let f = () => throw(A)

%%private(let b = 3)

Expand Down
83 changes: 83 additions & 0 deletions tests/tests/src/option_wrapping_test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
import * as Primitive_option from "rescript/lib/es6/Primitive_option.js";
import * as Stdlib_AsyncIterator from "rescript/lib/es6/Stdlib_AsyncIterator.js";

let x6 = {
x: 42
Expand All @@ -24,6 +26,54 @@ let x21 = new Date();

let x22 = /test/;

let x23 = new Map();

let x24 = new Set();

let x25 = new WeakMap();

let x26 = new WeakSet();

let x27 = new Float32Array([1.0]);

let x28 = Symbol("");

let x29 = new Error("");

let x30 = new ArrayBuffer(0);

let x31 = new DataView(new ArrayBuffer(0));

let x32 = new Map().values();

let x33 = Stdlib_AsyncIterator.make(() => Promise.resolve(Stdlib_AsyncIterator.value(true)));

let x34 = new Intl.ListFormat();

let x35 = new Intl.Segmenter();

let x36 = new Intl.Segmenter().segment("");

let x37 = new Intl.DateTimeFormat();

let x38 = new Intl.NumberFormat();

let x39 = true;

let x40 = new Intl.Collator();

let x41 = new Intl.RelativeTimeFormat();

let x42 = new Intl.PluralRules();

let x43 = new Intl.Locale("en");

let x45 = Promise.resolve(true);

let x47 = {};

let x48 = Stdlib_Lazy.make(() => true);

let x1 = "hello";

let x2 = 1;
Expand All @@ -41,6 +91,13 @@ let x5 = {

let x12 = "test";

let x44 = [
1,
2
];

let x46 = /* [] */0;

export {
x1,
x2,
Expand All @@ -56,5 +113,31 @@ export {
x20,
x21,
x22,
x23,
x24,
x25,
x26,
x27,
x28,
x29,
x30,
x31,
x32,
x33,
x34,
x35,
x36,
x37,
x38,
x39,
x40,
x41,
x42,
x43,
x44,
x45,
x46,
x47,
x48,
}
/* x20 Not a pure module */
28 changes: 28 additions & 0 deletions tests/tests/src/option_wrapping_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,31 @@ let x12 = Some(Nullable.Value("test"))
let x20 = Some(Jsx.null)
let x21 = Some(Date.make())
let x22 = Some(/test/)
let x23 = Some((Map.make(): Map.t<string, string>))
let x24 = Some((Set.make(): Set.t<string>))
let x25 = Some((WeakMap.make(): WeakMap.t<string, string>))
let x26 = Some((WeakSet.make(): WeakSet.t<string>))
let x27 = Some(Float32Array.fromArray([1.0]))
let x28 = Some(Symbol.make(""))
let x29 = Some(JsError.make(""))
let x30 = Some(ArrayBuffer.make(0))
let x31 = Some(ArrayBuffer.make(0)->DataView.fromBuffer)
let x32 = Some((Map.make(): Map.t<string, string>)->Map.values)
let x33 = Some(AsyncIterator.make(_ => AsyncIterator.value(true)->Promise.resolve))

let x34 = Some(Intl.ListFormat.make())
let x35 = Some(Intl.Segmenter.make())
let x36 = Some(Intl.Segmenter.make()->Intl.Segmenter.segment(""))
let x37 = Some(Intl.DateTimeFormat.make())
let x38 = Some(Intl.NumberFormat.make())
let x39 = Some(Intl.NumberFormat.Grouping.fromBool(true))
let x40 = Some(Intl.Collator.make())
let x41 = Some(Intl.RelativeTimeFormat.make())
let x42 = Some(Intl.PluralRules.make())
let x43 = Some(Intl.Locale.make("en"))

let x44 = Some((1, 2))
let x45 = Some(Promise.resolve(true))
let x46 = Some(list{})
let x47 = Some((Dict.make(): dict<string>))
let x48 = Some(Lazy.make(_ => true))