const s: string = 'foo';
const pass1 = (origin: string) => origin.concat(s);
const pass2 = (origin: string[]) => origin.concat(s);
type S = string | string[];
const error = (origin: S) => origin.concat(s);
The code above. I can call concat in a string or string[] type. So why TypeScript disallow call concat in string | string[] type?
The error is:
Cannot invoke an expression whose type lacks a call signature.
Type '((...strings: string[]) => string) | { (...items: ConcatArray<string>[]): string[]; (...items: (s...'
has no compatible call signatures.
Because they have different return type? But I think TS can infer error's type is S. Is it a intentional design? If it is, why?
const ret = error('msg'), what's the type ofret? TS infer it'sS, but it should bestring.