Description
The following function with overloads with JsDoc throws two errors. Written in pure TypeScript it passes the compiler. Is there a way to do this in JsDoc?
If there is no way, can I expect a fix in the future maybe or is it just technically impossible at the moment?
Thanks!
/**
* @type {{
* (init: "a"): () => string;
* (init: "b"): () => number;
* }}
*/
export const foo = (init) => {
return () => {
switch (init) {
case "a":
return "abc";
case "b":
return 10;
default:
throw Error("Invalid body method.");
}
};
};
console.log(foo("a")());
2322 [ERROR]: Type '(init: "a" | "b") => () => string' is not assignable to type '{ (init: "a"): () => string; (init: "b"): () => number; }'.
Call signature return types '() => string' and '() => number' are incompatible.
Type 'string' is not assignable to type 'number'.
export const handleResponse = (init) => {
~~~~~~~~~~~~~~
TS2322 [ERROR]: Type '() => 10 | "abc"' is not assignable to type '() => string'.
Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
return () => {