TypeScript: guide with Mix of Type and Interface for Function Parameters
I'm experimenting with I'm working with a type behavior when trying to pass a function as a parameter in TypeScript... Specifically, I have a function that accepts a callback, and I'm using a mix of type aliases and interfaces for the function parameters. Here's my code: ```typescript interface User { id: number; name: string; } type Callback = (user: User) => void; function processUser(user: User, callback: Callback) { callback(user); } const user = { id: 1, name: 'Alice' }; processUser(user, (u) => { console.log(u.name); }); ``` When I run this, TypeScript throws an behavior saying `Argument of type '(u: { id: number; name: string; }) => void' is not assignable to parameter of type 'Callback'`. I’ve confirmed that the `user` object conforms to the `User` interface, so I’m puzzled why the callback type is causing issues. I tried changing the type of `user` in the callback function to match the expected type: ```typescript processUser(user, (u: User) => { console.log(u.name); }); ``` But I still get the same behavior. I also experimented with using only interfaces for both the callback and the function parameters, but that didn't resolve the scenario either. I’m currently using TypeScript version 4.5.2 and I've tried checking my `tsconfig.json` for strict settings, but nothing seems to be amiss. Could someone guide to understand why TypeScript is throwing this behavior and how I might resolve it? This is part of a larger API I'm building. Has anyone else encountered this? What would be the recommended way to handle this?