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
package dashboard
type RevenueChartProps struct {
Title string `json:"title"`
Format func() string `json:"format"`
Totals map[int]string `json:"totals"`
}export default (el: HTMLElement) => {
el.textContent = "Revenue";
};gx check reports:
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 keysFix
- Change the field to a type with a mapping.
- For a value that the island does not read, give the field the tag
json:"-". - For a type with its own
MarshalJSONmethod, add a field with a plain type and fill it in the loader.