Typescript casting object's property

后端 未结 2 1670
予麋鹿
予麋鹿 2021-02-13 02:54

I\'m working with indexeddb and typescript. My issue is that TS doesn\'t seem to be able handle the event.target.result property. Case in point:

req         


        
2条回答
  •  旧巷少年郎
    2021-02-13 03:19

    You can also cast using the 'as' keyword like this

    interface MyCustomUserInterface {
        _id: string;
        name: string;
    }
    
    const userID = (req.user as MyCustomUserInterface)._id
    ...
    

    Cheers!

提交回复
热议问题