Arrays in type script

后端 未结 3 459
陌清茗
陌清茗 2021-02-05 00:52

I am finding difficulty declaring array in typescript and accessing it.

below is the code working for me

class Book {
    public BookId: number;
    publ         


        
3条回答
  •  借酒劲吻你
    2021-02-05 01:32

    A cleaner way to do this:

    class Book {
        public Title: string;
        public Price: number;
        public Description: string;
    
        constructor(public BookId: number, public Author: string){}
    }
    

    Then

    var bks: Book[] = [
        new Book(1, "vamsee")
    ];
    

提交回复
热议问题