Dear front-end colleagues, are you fed up with the interface with the back-end every day, adjusting the interface path and parameter transfer format? Tired of viewing backend documentation? Are you tired of checking and synchronizing the interface field changes after each update? It's time to make these jobs a little easier.
pnpm i api-typing-
set a script to run
get-typesinpackage.json{ "scripts": { "get-types": "get-types \"https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore-expanded.json\" \"./api-typing-meta.d.ts\"" } }the first argument is a openapi definition file, json format. the second argument is auto-generated type definetion file name with default value
api-typing-meta.d.ts -
run
pnpm run get-types
the type definition file would be generated in your project root.
-
after
api-typing-meta.d.tsgengrated in your project root. make sure yourtsconfig.jsoninclude this declare.{ "include": ["api-typing-meta.d.ts"] } -
import and enjoy it!
import { createHTTPClient } from "api-typing" createHTTPClient({ baseURL: "your baseURL" }) .post("choose/url/with/hint", { /** * request field with type-hint */ }) .then((d) => { /** * response field with type-hint */ })
