It's simple...
public static bool HasComponent <T>(this GameObject obj) where T:Component { return obj.GetComponent<T>() != null; }
Please note that you forgot
where T: component
part of the first line!
With this syntax error, the extension does not make sense: it always finds "some kind of component" because T is "empty".
Note.
Explanation "what the hell is an extension."
For those who read this, who are not familiar with the categories in c # .. that is, “Extensions” in c # ... here is a simple tutorial ...

Extensions are very important in Unity.
You use them in almost every line of code.
Basically in Unity, you do almost everything in the extension.
Note that since extensions are very common, the OP didn't even bother to show a wrapper class. Extensions are always in a file similar to the following:
public static class ExtensionsHandy // The wrapper class name is actually irrelevant - it is not used at all. // Choose any convenient name for the wrapper class. { public static bool HasComponent <T>(this GameObject obj) where T:Component { return obj.GetComponent<T>() != null; } public static bool IsNear(this float ff, float target) { float difference = ff-target; difference = Mathf.Abs(difference); if ( difference < 20f ) return true; else return false; } public static float Jiggle(this float ff) { return ff * UnityEngine.Random.Range(0.9f,1.1f); } public static Color Colored( this float alpha, int r, int g, int b ) { return new Color( (float)r / 255f, (float)g / 255f, (float)b / 255f, alpha ); } }
In the example, I included three typical extensions. Usually you have dozens or even hundreds of extensions in a project.
(You may prefer to group them into different HandyExtensions files or just have one huge HandyExtensions file.)
Each engineer and team has their own "common extensions", which they use constantly.
Here is a typical example of the issue of subtleties of extensions in C #.
Note that in older languages you usually call extensinos a “category”.
In c # it is an “extension”, but people constantly use the terms “category” or “extension”.
As I said, you constantly use them in Unity. Greetings
If you like things like this, here is a wonderful one:
// Here an unbelievably useful array handling category for games! public static T AnyOne<T>(this T[] ra) where T:class { int k = ra.Length; int r = UnityEngine.Random.Range(0,k); return ra[r]; }