简体   繁体   中英

how to to JSONify the code defined in typescript

Is there a way to JSONify the code defined in typescript?

export type ArticleList = ArticleListItem[];

export class ArticleListItem {
  title!: string;
  date?: string;
  key_type!: KeyTypes;
  path!: string;
  query: string = '';

  constructor( item: ArticleListItem ) {
    Object.assign( this, item );
  }
}

I would like to change the above typescript code to JSON.

You can use JSON.stringify(new ArticleListitem('x')) method to get the json. Refer - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM