Is there a way to improve editor autocomplete when calling a function that returns a union type?
For instance, in the given code snippet, after invoking
getProperty<ColorfulOrCircle>()
(line 14), the variable b
should display the accessible properties, but it is not happening.
1. interface Colorful {
2. color: string;
3. }
4. interface Circle {
5. radius: number;
6. }
8. type ColorfulOrCircle = Colorful | Circle;
10. function getProperty<T>(cc: T): T {
11. return cc;
12. }
14. let b = getProperty<ColorfulOrCircle>({color: "red"})
15. b. ; // NO AUTOCOMPLETE
Hovering over b.color
results in an error message:
https://i.sstatic.net/Cgklg.png
Pressing CTRL + BACKSPACE after b.
reveals only 'random' words.
https://i.sstatic.net/DdOOX.png
What changes should be made to the function to enhance intellisense?