How to convert a json to a typescript interface?

前端 未结 3 1572
野趣味
野趣味 2021-01-03 08:17

Given a JSON output of an api:

{
    \"id\": 13,
    \"name\": \"horst\",
    \"cars\": [{
        \"brand\": \"VW\",
        \"maxSpeed\": 120,
        \"is         


        
3条回答
  •  醉话见心
    2021-01-03 08:44

    You can use an npm module instead of the web hosted solution:

    https://www.npmjs.com/package/json-schema-to-typescript

    If your JSON comes from an HTTP API and the API has an swagger code definition, you can generate a TypeScript client:

    https://github.com/swagger-api/swagger-codegen#api-clients

    If you json comes from a Java ot .Net backened, you can generate TypeScript from Java or C# classes:

    http://type.litesolutions.net

    https://github.com/raphaeljolivet/java2typescript

提交回复
热议问题