I am a beginner in Typescript and JavaScript trying to understand a code. I encounter "< >" at several places in the code, as described in an example below.
(value: any, manager: ManagerBase<any>|undefined)
Why we use "< >" in typescript.
Thanks
I am a beginner in Typescript and JavaScript trying to understand a code. I encounter "< >" at several places in the code, as described in an example below.
(value: any, manager: ManagerBase<any>|undefined)
Why we use "< >" in typescript.
Thanks
ManagerBase is a generic type. It uses a parameter for a type in its definition (not present in the code you posted).
Let's say we have the type Sample<T> defined like this:
type Sample<T> = T[];
This makes Sample<T> an alias of the type "array of values of type T". The type Sample<number> is the same as number[], Sample<string> is the same as string[] and so on. Sample<any> is the same as any[].
In the code you posted, the type ManagerBase<any> uses any as the value of T.
Read about "generics" in the TypeScript handbook.
This symbol is used to specify the type when using generics. See the official TypeScript-Documentation for further information: https://www.typescriptlang.org/docs/handbook/generics.html