I now have a generic class Graph<T> ,
class Graph<T>{
protected _primaryKey?:string
protected _isDirected:boolean
constructor(isDirected=false,primaryKey?:string){
this._isDirected=isDirected
this._primaryKey=primaryKey
}
addVertex(v:T):this{
// todo
return this
}
}
// here are some examples
new Graph<string>() // ok
new Graph<number>() // ok
new Graph<{a:number}>() // type error:primaryKey is required
now I want it to pass primaryKey when T is of object type, but not when T is of other types. What do I do?