2017-08-29 99 views
2

我想創建一個打字稿DOC發電機JSON模式,但這樣做,我需要解析打字稿文件到的東西更容易閱讀生成打字稿

EX:

"Command": { 
    "description": "A command object for the command handler", 
    "constructor": [ 
     { 
     "name": "name", 
     "type": "string", 
     "optional": false, 
     "default": null, 
     "description": "Name of the command" 
     }, 
     { 
     "name": "callback", 
     "type": "(event: CommandContext) => void", 
     "optional": false, 
     "default": null, 
     "description": "Callback for the command" 
     } 
    ], 
    "properties": [ 
     { 
     "name": "name", 
     "description": "Name of the command", 
     "type": "string" 
     }, 
     { 
     "name": "fullname", 
     "description": "Fullname of the command", 
     "type": "string" 
     } 
    ], 
    "methods": [ 
     { 
     "name": "canRun", 
     "description": "Checks all permission checks and verifies if a command can be run", 
     "parameters": [ 
      { 
      "name": "context", 
      "type": "CommandContext", 
      "optional": false, 
      "default": null, 
      "description": "The context for the command", 
      "returns": "PermissionCheckResult" 
      } 
     ] 
     } 
    ], 
    "events": null 
    } 

會來自這樣的事情

export declare class Command { 
    /** 
    * Name of the command 
    */ 
    name: string; 
    /** 
    * Fullname of the command 
    */ 
    fullname: string; 
    /** 
    * Create a command 
    * @param name - Name of the command 
    * @param callback - Callback for the command 
    */ 
    constructor(name: string, callback: (event: CommandContext) => void); 
    /** 
    * Checks all permission checks and verifies if a command can be run 
    * @param context - The context for the command 
    */ 
    canRun(context: CommandContext): boolean; 
} 

我將如何做到這一點,最好在瀏覽器中,但如果這是不可能的我也能做到這一點如何使用Node.js

+1

沒有成熟的解決方案。一些鏈接:https://github.com/YousefED/typescript-json-schema,https://github.com/Microsoft/TypeScript/issues/14419,https://github.com/Microsoft/TypeScript/issues/3628 #issuecomment-298236279 – Paleo

回答

0

TypeDoc有類似的功能,你可以使用--json標籤,以獲取有關JSON格式的模塊數據

這不正是我一直在尋找,但可用來完成同樣的事情