Skip to content
Gx
GitHub

GX4004: signal type does not match the action field

An action input field and the signal that it reads have different types.

Cause

An action input field and the signal that it reads have different types.

Example

cart/Button.gx
package cart

import "app/cart/route"

signals {
  Qty string = "1"
}

<button on:click={route.Add{}}>Add</button>
cart/cart.go
package cart

import (
	"github.com/alternayte/gx"
	"app/cart/route"
)

var Add = gx.Action(func(c *gx.Ctx, in route.Add) error { return nil })
cart/route/route.go
package route

import "github.com/alternayte/gx"

type Add struct {
	gx.Route `POST /cart/add`
	Qty      int `signal:"qty"`
}

func (in *Add) Rules() gx.Rules {
	return gx.Rules{gx.Field(&in.Qty, gx.Min(1))}
}

gx check reports:

gx check
cart/Button.gx:9:9: GX4004: field "Qty" has type "int" but signal "qty" has type "string"

Fix

Give the field and the signal the same type.