Type Definitions
It is possible, but not required, to generate TypeScript type definitions from Go structs with types.Generate[T]()
, where T
is the type you wish to generate.
-
Define your Go types.
lib/routes/welcome/types.go package welcometype Props struct {Message string `json:"message"`Error string `json:"error"`} -
Call
types.Generate[T]()
.lib/routes/welcome/types.go package welcomefunc init() {_ = types.Generate[Props]()}type Props struct {Message string `json:"message"`Error string `json:"error"`} -
Generate types
Terminal window frizzante -gtypesThis will generate your type definitions in
.gen/types
..gen/types/main/lib/routes/welcome/Props.d.ts export type Props = welcome.Propsexport declare namespace welcome {export type Props = {message: stringerror: string}}