interface User {
name: string;
colors: string[];
}
function printUser(user: User) {
console.log(user);
}
printUser({'jonathan ',['red','blue']}); \\ PASSING CORRECT PARAMS
How do I pass the param to printUser
get it printed the whole object in the console log?
printUser({ name: 'jonathan ', colors: ['red', 'blue']});
You have to also pass keys in object, not only values.
Update your function call like
const user1: User = { name: 'jonathan ', colors: ['red', 'blue'] };
printUser(user1);
or
printUser({ name: 'jonathan ', colors: ['red', 'blue'] });
You have to pass data in the same type ie User
as you are expecting in printUser
function;
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.