During type-checking time, I have a rule to enforce regarding the parameters that can be passed to my function.
The type is described in the following code snippet:
type CheckConf<TConf extends SupportedConf> = {
[Key in keyof TConf]: TConf[Key] extends SupportedConf[string]
? [Key, [Key, Key]]
: TConf[Key]; ⬅⬅⬅
};
This type is used as shown below:
declare function check<TConf extends SupportedConf>(
params: CheckConf<TConf>
): TConf[keyof TConf];
check({ a: ["a", ["a", "a"]], b: ["b", ["b", "b"]] });
check(
{ a: ["a", ["a", "b"]] }
);
check({ a: ["a", true] });
For more details and interactive testing, visit this live playground link.
I successfully implemented the CheckConf
type but encountered difficulty with understanding the behavior of using never
in certain contexts. What theory explains this behavior, and why is never
not suitable in these cases?