如何将定义打字稿转换为json?

时间:2016-08-01 05:54:57

标签: json typescript

我希望将d.ts文件的内容转换为json格式,即我希望d.ts文件中的函数框架以json或抽象语法树显示。我想知道如何继续以实现这一目标。简而言之,我只想在json文件中显示该特定函数的存在。

1 个答案:

答案 0 :(得分:2)

您基本上使用typescript编译器api / Program来获取let fileManager = FileManager.default let url = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "YOUR_GROUP_ID")?.appendingPathComponent("logo.png") // Write to Group Container if !fileManager.fileExists(atPath: url.path) { let image = UIImage(named: "name") let imageData = UIImagePNGRepresentation(image!) fileManager.createFile(atPath: url.path as String, contents: imageData, attributes: nil) } // Read from Group Container - (PushNotification attachment example) // Add the attachment from group directory to the notification content if let attachment = try? UNNotificationAttachment(identifier: "", url: url!) { bestAttemptContent.attachments = [attachment] // Serve the notification content self.contentHandler!(self.bestAttemptContent!) } 并使用SourceFile来访问其所有子节点。

更多

文档:https://basarat.gitbooks.io/typescript/content/docs/compiler/ast-tip-children.html

已显示AST的OSS工具:https://basarat.gitbooks.io/alm/content/features/ast.html

相关问题