What does enclosing a class in angle brackets "<>" mean in TypeScript? -


i new typescript , loving lot, how easy oop in javascript. stuck on trying figure out semantics when comes using angle brackets.

from docs, have seen several example

interface counter {     (start: number): string;     interval: number;     reset(): void; }  function getcounter(): counter {     let counter = <counter>function (start: number) { };     counter.interval = 123;     counter.reset = function () { };     return counter; } 

and

interface square extends shape, penstroke {     sidelength: number; }  let square = <square>{}; 

i having trouble understanding means or way think of/understand it.

could please explain me?

that's called type assertion or casting.

these same:

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

example:

interface props {     x: number;     y: number;     name: string; }  let = {}; a.x = 3; // error: property 'x' not exist on type `{}` 

so can do:

let = {} props; a.x = 3; 

or:

let = <props> {}; let a: props = {}; 

which same


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -