Check if object correctly implements interface

前端 未结 3 855
予麋鹿
予麋鹿 2020-12-03 22:49

Interface:

export interface User {
  id: number;
  name: string;
  foo: string;
  bar: string;
}

How do I check that a returned object from

3条回答
  •  北海茫月
    2020-12-03 23:25

    Here is an example:

    getUser(user: User) {
        return user;
    }
    

    Just make sure that you pass a user of type User in your function

提交回复
热议问题