Return anonymous class in TypeScript

Suppose we have a .NET core action that returns Ok(new { id, name }).
Now we need to get the value in a TypeScript code without creating a class definition explicitly.

We can use this simple notation:

httpClient.get<{id: number, name: string}>('api/somewhere')

 

Post a Comment

Previous Post Next Post