Skip to content
Gx
GitHub

GX6002: island prop type has no TypeScript mapping

A field of the props struct of an island has a type that the compiler cannot write as JSON and as a TypeScript type.

Cause

The compiler writes the props of an island as JSON, and it writes the TypeScript type of the props from the Go struct. A field of the props struct holds a type with no mapping. The message gives the path to the value and the reason.

These types have a mapping: a string, a number, a bool, time.Time, a slice, an array, a map with string keys, a struct and a pointer to one of them. A string type with constants becomes a union.

Example

dashboard/charts.go
package dashboard

type RevenueChartProps struct {
	Title  string         `json:"title"`
	Format func() string  `json:"format"`
	Totals map[int]string `json:"totals"`
}
dashboard/RevenueChart.ts
export default (el: HTMLElement) => {
  el.textContent = "Revenue";
};

gx check reports:

gx check
dashboard/charts.go:5:2: GX6002: island prop "Format" has type "func() string": this type has no mapping
dashboard/charts.go:6:2: GX6002: island prop "Totals" has type "map[int]string": a map needs string keys

Fix

  1. Change the field to a type with a mapping.
  2. For a value that the island does not read, give the field the tag json:"-".
  3. For a type with its own MarshalJSON method, add a field with a plain type and fill it in the loader.