Typescript supports Conditional Types.
But when I try to set value of op as string, it gives me error, how do I check the type and assign value?
export const t = <IsMulti extends boolean = false>(): void => {
const value = 'test';
type S = string;
type D = IsMulti extends true ? S[] : S;
const op: D = value;
console.log(op);
};
Error: Type 'string' is not assignable to type 'D'.
I have even tried adding a parameter of same type IsMulti and adding check based on it
export const t = <IsMulti extends boolean = false>(isMulti: IsMulti): void => {
const value = 'test';
type S = string;
type D = IsMulti extends true ? S[] : S;
if (!isMulti) {
const op: D = value;
console.log(op);
}
};