What are the greater than and less than tags used for when wrapping

I'm new to Angular 2 and have seen code like the following:

  this._tags = <BehaviorSubject<Tag[]>>new BehaviorSubject([]);

What I can't seem to find is the use of "<>".

What is the purpose of wrapping BehaviorSubject and Tag[] in "<>"?

1 answer

  • answered 2017-06-17 18:28 CharanRoot

    Its called Type Assertion. Using Type Assertion Typescript will convert one data type to another data type.

    Example var anyvalue: any; var stringValue = anyvalue;

    In the this example Typescript will convert anyvalue to string value.

    this._tags = <BehaviorSubject<Tag[]>>new BehaviorSubject([]);

    In this code your converting BehaviorSubject of any array type to BehaviorSubject of Tag array.

    Type Assertion vs. Type Casting

    Type assertions are purely a compile time and Type Casting will support run time.