What does typescript generic class mean?

class GenericNumber<T> {
  zeroValue:T,
  add:(x:T,y:T)=>T
}
let myGenericNumber = new GeneriNumber<number>()

let result2 = myGenericNumber.add(1, 2);
console.log(result2)

ask why there is no add method, and how should I understand the introspection class

Apr.13,2021

this has nothing to do with the paradigm. You only define the interface of add above, but it is not implemented. The
add method has no actual content, so it is sure to prompt add is not a function when called.

The

paradigm is more used to tell developers what kind of parameters this function, this class, supports and what types of return values can be obtained.

More will appear in

interface .

Menu