What is `assert` used for?

GPT suggested using | _ => assert false when using switch pattern matching on a string


switch text {
  | "Apple" => Apple
  | _ => assert false

where can I read documentation or know what it is doing?

You can use it as a todo flag, then the ide would work normally😅

It throws the Assert_failure exception. In my opinion it should be removed from ReScript.


It’s better to use panic if you’re using ReScript Core, as that throws a real JS error which will give you a stack trace etc:



super, I’ll use this instead, thanks

Why RescriptCore chose panic? assert also has a stack trace. It also shows the file and location in the .res file.

  RE_EXN_ID: 'Assert_failure',
  _1: [ 'assert.res', 6, 9 ],
  Error: Error
      at file:///home/pedro/Desktop/learning-rescript/src/assert.bs.mjs:18:16
      at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
      at async Promise.all (index 0)
      at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
      at async loadESM (node:internal/process/esm_loader:91:5)
      at async handleMainPromise (node:internal/modules/run_main:65:12)