You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the migration to @rescript/core, the above code fragment has e with type exn and err now with type unknown which results in the following compile error in reference to err being passed into Exn.message:
This has type: unknown
Somewhere wanted: RescriptCore.Exn.t (defined as Js_exn.t)
This worked before the migration. Thanks.
EDIT: I modified JsError to Exn.Error and it compiled, but I don't think this code properly handles Js exceptions. I looked in the rescript documentation and did not find much.
EDIT: I modified JsError to Exn.Error and it compiled, but I don't think this code properly handles Js exceptions. I looked in the rescript documentation and did not find much.
This is a good gotcha for anyone already using rescript-promise and I'll add it to the migration readme as soon as we've sorted this out.
EDIT: More context. rescript-promise used to define its own JsError exception because at the time the compiler didn't have the necessary internal APIs to handle JS exceptions the way rescript-promise wanted. These internal APIs have shipped since then, so Core uses them instead, which is the way going forward.
I migrated our entire corporate code base in a branch (for now) to see what came up.
Our starting point was -open Belt and -open ReScriptJs (bloodyowl's).
I decided to switch to -open RescriptCore only and not open Belt, to make it clearer where we still use Belt.
Some observations (not issues in my opinion):
I had expected ReScriptCore instead of RescriptCore to be the name of the module, consistent with project branding
Because we already used bloodyowl's rescript-js and -open Belt, I assumed we could not use the automated migrations. If this is incorrect, we may want to add a note about this for other users.
Because of our -opens, Js.String.Split used to refer to bloodyowl's binding and now refers to the binding shipped with the compiler, which has the same signature but a different implementation. This caused erroneous behaviour at runtime (fixed by changing to String.split)
After noticing this I decided to remove the Js. prefix everywhere
Belt.Array.concatMany (which was Array.concatMany in our codebase) and RescriptCore.Array.concatMany (which is now Array.concatMany) have the same name but different signatures; I had to migrate them to RescriptCore's Array.flat
Belt.Array.joinWith had an extra 't => string parameter which RescriptCore.Array.joinWith does not have (an improvement in my opinion; all but one place in our codebase passed x => x)
Belt.Array.mapWithIndex passes the index as the first argument, while RescriptCore.Array.mapWithIndex passes the index as the second argument
Belt.Array.slice takes ~offset and ~len, while RescriptCore.Array.slice takes ~start and ~end, which can be a gotcha
Same for ReScriptJs.String.substr (~start and ~length), which is not present in RescriptCore, versus RescriptCore.String.substring (~start and ~end)
Belt.Array.sliceToEnd takes a positional argument while RescriptCore.Array.sliceToEnd takes a labeled argument (~start)
I decided to use Array.getUnsafe instead of Array.getExn (which does not exist anymore in RescriptCore) in some places
There now exists a module Date and module Error in global scope, which are shadowed by some of my own modules
I passed Belt.Int.fromString to Array.map, but RescriptCore.Int.fromString takes a optional ~radix argument which created a warning
Some renamed types:
Js.Date.Time.t -> Date.time
Some renamed functions:
Js.String.replaceString -> String.replace
keep -> filter
keepMap -> filterMap
getBy -> find
getIndexBy -> findIndexOpt (would have preferred if findIndex returned an option<int>)
Js.JSON.Decode.classify -> JSON.Classify.classify
Js.Global.setTimeout -> setTimeout (don't really like these functions in the global scope)
Places where we still use Belt after the migration:
Belt.Map and functions (extensively)
Belt.Map.String and functions
Belt.Map.Int and functions
Belt.Set and functions (extensively)
Belt.Set.String and functions
Belt.Id (for Map and Set)
Belt.SortArray.stableSortBy
Belt.Array.zip
Belt.Array.unzip
Belt.Array.range
Belt.Array.partition
Belt.Array.make
Belt.Array.makeBy
Reacted by Gabriel Nordeborn, Gorka Cesium and Freddy Harris
I experienced many things described by @Minnozz (but I didn't -open Belt on my codebase)
I also still use Belt.Map.String and Belt.Set.String
And for Belt.Array : partition, range and slice (because the ~offset/~len, in some case, is more useful than the ~start/~end to express intention)
Sort
The migration from Belt.SortArray.stableSortBy to Array.toSorted was a bit tricky because:
need to change all int to float
need to check order because Js.String.localeCompare("a", "b") return 1 while RescriptCore.String.localeCompare("a", "b") return -1
toSorted is well implemented on browsers, but it is'nt on hermes (react-native) yet, I needed to add a polyfill for it (just adding import "array.prototype.tosorted/auto"; at the top of index.js file)
But I'm happy to finally tackled this task 😅
Thank's everyone for the work on Rescript! I still love this langage since I used it 6 years ago (it was Reason back then but, Rescript go to the good direction imho)
Activity
whitchapman commentedon Feb 9, 2023
After the migration to @rescript/core, the above code fragment has
ewith typeexnanderrnow with typeunknownwhich results in the following compile error in reference toerrbeing passed intoExn.message:This worked before the migration. Thanks.
EDIT: I modified
JsErrortoExn.Errorand it compiled, but I don't think this code properly handles Js exceptions. I looked in the rescript documentation and did not find much.zth commentedon Feb 10, 2023
This is the correct way to do it. Does it not work for you? We have tests with that same behavior: https://github.com/rescript-association/rescript-core/blob/main/test/PromiseTest.res#L46-L71
This is a good gotcha for anyone already using
rescript-promiseand I'll add it to the migration readme as soon as we've sorted this out.EDIT: More context.
rescript-promiseused to define its ownJsErrorexception because at the time the compiler didn't have the necessary internal APIs to handle JS exceptions the wayrescript-promisewanted. These internal APIs have shipped since then, soCoreuses them instead, which is the way going forward.Minnozz commentedon Feb 10, 2023
I migrated our entire corporate code base in a branch (for now) to see what came up.
Our starting point was
-open Beltand-open ReScriptJs(bloodyowl's).I decided to switch to
-open RescriptCoreonly and not open Belt, to make it clearer where we still use Belt.Some observations (not issues in my opinion):
ReScriptCoreinstead ofRescriptCoreto be the name of the module, consistent with project branding-open Belt, I assumed we could not use the automated migrations. If this is incorrect, we may want to add a note about this for other users.-opens,Js.String.Splitused to refer to bloodyowl's binding and now refers to the binding shipped with the compiler, which has the same signature but a different implementation. This caused erroneous behaviour at runtime (fixed by changing toString.split)Js.prefix everywhereBelt.Array.concatMany(which wasArray.concatManyin our codebase) andRescriptCore.Array.concatMany(which is nowArray.concatMany) have the same name but different signatures; I had to migrate them to RescriptCore'sArray.flatBelt.Array.joinWithhad an extra't => stringparameter whichRescriptCore.Array.joinWithdoes not have (an improvement in my opinion; all but one place in our codebase passedx => x)Belt.Array.mapWithIndexpasses the index as the first argument, whileRescriptCore.Array.mapWithIndexpasses the index as the second argumentBelt.Array.slicetakes~offsetand~len, whileRescriptCore.Array.slicetakes~startand~end, which can be a gotchaReScriptJs.String.substr(~startand~length), which is not present in RescriptCore, versusRescriptCore.String.substring(~startand~end)Belt.Array.sliceToEndtakes a positional argument whileRescriptCore.Array.sliceToEndtakes a labeled argument (~start)Array.getUnsafeinstead ofArray.getExn(which does not exist anymore in RescriptCore) in some placesmodule Dateandmodule Errorin global scope, which are shadowed by some of my own modulesBelt.Int.fromStringtoArray.map, butRescriptCore.Int.fromStringtakes a optional~radixargument which created a warningJs.Date.Time.t->Date.timeJs.String.replaceString->String.replacekeep->filterkeepMap->filterMapgetBy->findgetIndexBy->findIndexOpt(would have preferred iffindIndexreturned anoption<int>)Js.JSON.Decode.classify->JSON.Classify.classifyJs.Global.setTimeout->setTimeout(don't really like these functions in the global scope)Belt.Mapand functions (extensively)Belt.Map.Stringand functionsBelt.Map.Intand functionsBelt.Setand functions (extensively)Belt.Set.Stringand functionsBelt.Id(for Map and Set)Belt.SortArray.stableSortByBelt.Array.zipBelt.Array.unzipBelt.Array.rangeBelt.Array.partitionBelt.Array.makeBelt.Array.makeByzth commentedon Feb 10, 2023
@Minnozz fantastic and insightful write up, thank you!
vasco3 commentedon Feb 14, 2023
I found out
Js.Math._PIis nowMath.Constants.piI also was using
open Beltin many files so I removed that and addedBelt.to all theArrayso combo can work better.Array.map(->Belt.Array.mapCombi missed to flip the index in
Array.mapWithIndex.Freddy03h commentedon Jan 24, 2025
2 years later, in finally migrated to Core too!
Belt
I experienced many things described by @Minnozz (but I didn't
-open Belton my codebase)I also still use
Belt.Map.StringandBelt.Set.StringAnd for
Belt.Array:partition,rangeandslice(because the~offset/~len, in some case, is more useful than the~start/~endto express intention)Sort
The migration from
Belt.SortArray.stableSortBytoArray.toSortedwas a bit tricky because:Js.String.localeCompare("a", "b")return1whileRescriptCore.String.localeCompare("a", "b")return-1toSortedis well implemented on browsers, but it is'nt on hermes (react-native) yet, I needed to add a polyfill for it (just addingimport "array.prototype.tosorted/auto";at the top ofindex.jsfile)But I'm happy to finally tackled this task 😅
Thank's everyone for the work on
Rescript! I still love this langage since I used it 6 years ago (it was Reason back then but, Rescript go to the good direction imho)