Generics
· One min read
Example with a class
class HoldAnything<T> {
// T is the name usually given to the generic 'type of data'
data: T
}
const holdNumber = new HoldAnything<number>()
holdNumber.data = 123
const holdString = new HoldAnything<string>()
holdString.data = 'Hello Wall-e'