main.go
Go
 1package main
 2
 3import (
 4	"fmt"
 5	"net/http"
 6)
 7
 8func main() {
 9	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
10		fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
11	})
12	http.ListenAndServe(":8080", nil)
13}
user.ts
TypeScript
interface User {
  id: number;
  name: string;
  role: "admin" | "user";
}

async function fetchUser(id: number): Promise<User> {
  const res = await fetch("/api/users/" + id);
  return res.json();
}