// compiles successfully
type a = {
href?: string
}
Creating an empty record “out of it” is of course not possible:
let x = {}
// or the suggestive annotation
let x : a = {}
// raises
// Error: This let-binding misses an expression
Is it correct to conclude that the experimental optional record fields introduced in v10 (ReScript 10.0 | ReScript Blog) cannot create objects with all optional fields?
Empty record is introduced in 10.1
, which is not released yet. But available as rescript@next
.
2 Likes
That’s great!
I wonder what the semantics of specifying an empty record are.
I just installed rescript@next
, but after restarting the LSP (and VS Code), the following snippet still gives an error:
type attrs = {class?: string}
@module("@hyperapp/html") @val external aside: (attrs, array<vnode>) => vnode = "aside"
open Hyperapp.Html
let _ = aside({}, [text("Contact info"])
~
// Error (squiggly red under the closing brace of the empty {}): Missing expression
This self-contained example works for me:
type attrs = {class?: string}
type vnode
module Hyperapp = {
module Html = {}
}
let text = (_) => assert false
@module("@hyperapp/html") @val external aside: (attrs, array<vnode>) => vnode = "aside"
open Hyperapp.Html
let _ = aside({}, [text("Contact info")])
package.json:
"dependencies": {
"rescript": "^10.1.0-alpha.2"
}
2 Likes
Started working for me too. Thank you.
P.S.:This feature still raises the above mentioned error under the extension v1.6.0. I upgraded to the pre-release version and now the error is gone. So until rescript v10.1 stable lands, rescript@latest
along with rescript-vscode pre-release should do the job.
1 Like