I have come across this TypeScript function:
get_value(): T | undefined {
let TValue: T | undefined;
return TValue;
}
get_value() // result => undefined
The return type can be either "T" or "undefined", which means the function always returns undefined. How can I modify it to return a string value? If I try to change the return value to a string, like in the following example, it gives an error:
export abstract class NVap<T> {
abstract get_value((): T | undefined;
}
export class Vap<T> extends NVap<T> {
get_value(): T | undefined {
let TAa: T | undefined;
// assign a string value to the variable
TAa = "some str";
return TAa;
}
}
let task = new Vap();
task.get_value();
// result => error TS2322: Type '"some str"' is not assignable to type 'T | undefined'.
Any insights on how to solve this issue would be greatly appreciated!