Skip to content
Gx
GitHub

GX2004: static value for a typed prop

A static string is given to a prop that has a type other than string.

Cause

A static string is given to a prop that has a type other than string. Gx does not change a string into a constant.

Example

ui/card/Card.gx
package card

props {
  Title   string
  Variant Variant = Plain
}

<article data-variant={string(p.Variant)}>{p.Title}</article>
ui/card/Page.gx
package card

<Card title="News" variant="raised" />
ui/card/variant.go
package card

// Variant is the visual style of a card.
type Variant string

const (
	Plain  Variant = "plain"
	Raised Variant = "raised"
)

gx check reports:

gx check
ui/card/Page.gx:3:20: GX2004: attribute "variant" is a static string but prop "Variant" has type "Variant"

Fix

Pass the constant as an expression, for example variant={card.Raised}.