如何从JSON对象生成打字稿类型(非接口)

时间:2020-05-14 11:48:17

标签: json typescript

我发现了很多在线工具和VS Code扩展,它们可以从 JSON 对象生成打字稿接口,但是找不到用于生成 types < / strong>来自 JSON 对象(我知道两者之间没有显着差异)。

简单的例子

{
  "configuration": {
    "logging": {
      "path" : "logs",
      "extension" : "json"
    }
  }
}

成为:

declare module namespace {

    export interface Logging {
        path: string;
        extension: string;
    }

    export interface Configuration {
        logging: Logging;
    }

    export interface RootObject {
        configuration: Configuration;
    }

}

我需要的是:

declare module namespace {

    export type Configuration = {
      logging: Logging
    };

    export type Logging = {
      path: string,
      extension: string,
   };

    export type RootObject {
      configuration: Configuration;
    }

}

0 个答案:

没有答案