`fun <T> T?.foo() { … }` may be what you are...
# getting-started
d
fun <T> T?.foo() { … }
may be what you are looking for?