What does enclosing a class in angle brackets “” mean in TypeScript?

That’s called Type Assertion or casting.

These are the same:

let square = <Square>{};
let square = {} as Square;

Example:

interface Props {
    x: number;
    y: number;
    name: string;
}

let a = {};
a.x = 3; // error: Property 'x' does not exist on type `{}`

So you can do:

let a = {} as Props;
a.x = 3;

Or:

let a = <Props> {};

Which will do the same

Leave a Comment