#Lustre quickstart guide `Private type used in public interface` error

1 messages · Page 1 of 1 (latest)

tardy sequoia
#

Yello, looking at how luste looks like, so I just copy pasted stuff from the quickstart guide, and I can't get it to work quite.

pub fn main() {
  let app = lustre.application(init, update, view)
  let assert Ok(_) = lustre.start(app, "#app", Nil)
}

type Model {
  Model(total: Int, cats: List(Cat))
}

type Cat {
  Cat(id: String, url: String)
}

fn init(_args) -> #(Model, Effect(Msg)) {
  let model = Model(total: 0, cats: [])

  #(model, effect.none())
}

type Msg {
  UserClickedAddCat
  UserClickedRemoveCat
  ApiReturnedCats(Result(List(Cat), rsvp.Error))
}

fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
  ...
}

fn get_cat() -> Effect(Msg) {
  ...
}

/*error: 
Private type used in public interface

The following type is private, but is being used by this public export.

    Msg

Private types can only be used within the module that defines them.
*/
pub fn view(model: Model) -> Element(Msg) {
  ....
}

Am I missing something?

karmic swallow
#

Welcome!

in Gleam, every function returns the result of the last expression in it.
Your main functions last expression is let assert Ok(_) = lustre.start(app, "#app", Nil)
the resulting value you get from there is a Result(Runtime(Msg), Error), so your main return type includes your msg type!

the canonical solution is to add an explicit Nil return to your main function, like this:

pub fn main() {
  let app = lustre.application(init, update, view)
  let assert Ok(_) = lustre.start(app, "#app", Nil)

  Nil
}
#

if there is a main function in the quickstart that doesn't do that, we should change that 😄

tardy sequoia
#

oh it's there

#

I just ommited to stay within line limit of disc

karmic swallow
#

oh I see

drifting zinc
#

remove the pub in front of the view function

karmic swallow
#

sorry I didn't read on after spotting that 😄

karmic swallow
#

but yes as Jen said you have the same problem in your view function
the function is public, but your Msg type is not ^.^

tardy sequoia
#

wrong reply

#

Yes it was pub

#

Welp quickstart has a typo then

#

But thanks :)

karmic swallow
#

yep