我有一个 TypeScript 代码生成场景,我在其中构造了一个 AST,然后将其打印并保存到一个文件中。例如,打印的类声明元素聚集在一起。怎样才能实现在新方法/构造函数声明之后插入换行符的漂亮打印类型,并且也许可以在新行中堆叠扩展方法?
private baseUrl = "api/students";
constructor(private http: Http) { }
list(): Promise<Student[]> {
return this.http.get(this.baseUrl + "/").toPromise().then((response: Response) => response.json()).catch(this.handleError);
}
get(id: number): Promise<Student> {
return this.http.get(this.baseUrl + ("/" + id)).toPromise().then((response: Response) => response.json()).catch(this.handleError);
}
任何现有的 API 就足够了,或者有没有办法在声明后手动插入一些尾随琐事?