Skip to content

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.

  1. Define your Go types.

    lib/routes/welcome/types.go
    package welcome
    type Props struct {
    Message string `json:"message"`
    Error string `json:"error"`
    }
  2. Call types.Generate[T]().

    lib/routes/welcome/types.go
    package welcome
    func init() {
    _ = types.Generate[Props]()
    }
    type Props struct {
    Message string `json:"message"`
    Error string `json:"error"`
    }
  3. Generate types

    Terminal window
    frizzante -gtypes

    This will generate your type definitions in .gen/types.

    .gen/types/main/lib/routes/welcome/Props.d.ts
    export type Props = welcome.Props
    export declare namespace welcome {
    export type Props = {
    message: string
    error: string
    }
    }