Skip to content
Playground(another site)

bynk.types.field_name_bad_arg

Error A field's @name does not take exactly one string literal, or a String constant bound to one.

@name renames a field's key on an HTTP request, and the compiler reads that key at compile time, so it takes exactly one string literal, or a String constant bound to one: not a number, a computed value, a second argument or none. A constant must be declared exactly String (not a refined type) and bound to a string literal or to another such constant. Write the key as a literal, as in @name("__Host-sid"), or name it once with a constant.

Example

type Filter = {
@name(1) pageSize: Option[Int], // ✗ not a string literal
}
const PageKey: String = "page-size"
type Filter = {
@name(PageKey) pageSize: Option[Int], // ✓ a `String` constant bound to a literal
}
type Filter = {
@name("page-size") pageSize: Option[Int], // ✓
}

In the Book

See also

  • The grammar rule it governs: record_field.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.field_name_bad_arg shows the same from the installed toolchain, without a network.