How can I improve intellisense to support default values in TypeScript?
Given the following code snippet:
type Ns = "foo" | "bar"
function translate<N extends Ns = "foo">(ns?: N) {
return ns || "foo"
};
I need proper intellisense that allows both "foo" and "bar" as inputs, with "foo" being the default value when nothing is entered.
Currently, intellisense only suggests "foo" as an option upon typing, but it should also include "bar". See example below:
https://i.sstatic.net/jiDub.pngIf I input "f", intellisense correctly suggests "foo": https://i.sstatic.net/PeJXS.png This behavior is desirable.
However, entering "b" does not suggest "bar" in intellisense. It should provide a suggestion for "bar" as well. See example below:
https://i.sstatic.net/AMAZm.pngBoth "bar" and "foo" should be considered valid inputs: https://i.sstatic.net/A0jDk.png
If I remove the = "foo"
part from the code, intellisense works correctly but fails to recognize "foo" as the default value:
https://i.sstatic.net/6L5JI.png
https://i.sstatic.net/M1vuz.png
https://i.sstatic.net/Lc7P1.png
How can I customize types to ensure correct intellisense while indicating "foo" as the default value?
Refer to this simple example for context.
For more insights, explore this complex example.
Appreciate your help! <3