Given this function:
myFunc(object: string | null): string | null {}
I would like this function to be of return type string when the object is string, and return type of string | null when the object is of type string | null.
I have tried:
myFunc<T extends string | null>(object: T): T {
return "returnValue"; //Type '"returnValue"' is not assignable to type 'T'.
}
and
myFunc<T extends string & null>(object: T): T {
return "returnValue"; //Type '"returnValue"' is not assignable to type 'T'.
}
Both produce the same compile error. I have not found the correct syntax to do this.