generic type extends typescript code example
Example 1: typescript generic class
class Person {
name: T
age: U
hobby: C[]
constructor(name: T, age: U, hobby: C[]) {
this.name = name
this.age = age
this.hobby = hobby
}
}
const output = new Person('john doe', 23, ['swimming', 'traveling', 'badminton'])
console.log(output)
Example 2: how to make a generic variable in javascript
var x = 1;
var y = 1;
if (x == y) {
x = x + 1
}