"declare function"'s need to converted to single function.
AaronNGray opened this issue · 2 comments
AaronNGray commented
AFAICT "declare function"'s need to converted to single function.
For example :-
declare function didYouMean(suggestions: $ReadOnlyArray<string>): string;
declare function didYouMean(
subMessage: string,
suggestions: $ReadOnlyArray<string>,
): string;
// eslint-disable-next-line no-redeclare
export default function didYouMean(firstArg, secondArg?) { ... }
needs converting to :-
export default function didYouMean(firstArg: string | ReadonlyArray<string>, secondArg?:ReadonlyArray<string>): string { ... }
otherwise I am getting the error :-
error TS2384: Overload signatures must all be ambient or non-ambient.
AaronNGray commented
I am trying to work out how to go about this given the current structure of babel-plugin-flow-to-typescript.
There appears to be no context object passed through the visitors.
The other way would to do this as a separate "pass" at the Program level.
zxbodya commented
ideally this should be converted to:
function didYouMean(suggestions: ReadonlyArray<string>): string;
function didYouMean(
subMessage: string,
suggestions: ReadonlyArray<string>,
): string;
// eslint-disable-next-line no-redeclare
function didYouMean(firstArg, secondArg?):string { }
export default didYouMean;
there are are two issues to be fixed:
- remove
declare
- typescript supports function overrides without it(however,declare
should be removed only if the actual implementation is present) - separating
export
from function declaration - in typescript, it should be either on all declarations or separate from them.
I think the best place to do it would be exit()
in Program
visitor, implemented it here: zxbodya/flowts@a3032f2