-
Notifications
You must be signed in to change notification settings - Fork 46
Fails typescript parsing when having nested arrow functions #75
Comments
Thanks! It reproduces with the following integration test case: it('issue #75', () => {
const input = `
function doTheThing(cb) {
cb([1,2,3]);
}
doTheThing((results) => {
results.forEach((result) => console.log(result));
});
`;
expect(typeWiz(input)).toBe(`
function doTheThing(cb) {
cb([1,2,3]);
}
doTheThing((results: number[]) => {
results.forEach((result: number) => console.log(result));
});
`);
}); I will try to come up with a fix |
@urish I've stumbled on this error while using typewiz-webpack. Are you working on this? if not, can I have a go? |
Any thoughts here? I dug around in the source and it seems like somehow the parameters themselves are not getting annotated. The simplest test case I could come up with: (in it('should correctly handle nested arrow functions', () => {
const input = `(x=>y=>x+y+5)(10)(7)`;
expect(typeWiz(input)).toBe(`(x: number)=>(y: number) => x+y+5)(10)(7)`);
}); (the annotated result may be incorrect, it was just a guess) Here's an odd bit - if I just make if (ts.isArrowFunction(node)) {
if (!node.getSourceFile()) {
return false;
} then I get this interesting test failure:
pretty-printed, this evals to: (function(x) {
$_$twiz("x", x, 2, "c:/test.ts", '{"arrow":true,"parens":[1,2]}');
(function(y) {
$_$twiz("y", y, 5, "c:/test.ts", '{"arrow":true,"parens":[4,5]}');
x + y + 5;
});
})(10)(7); which seems wrong - it isn't applying the result of the first function to the second.. |
Released this fix as part of typewiz 1.2.1 |
Versions:
This is a stripped down version of some code I have that causes the error
However I've managed to strip it back even further (to eliminate it being something related to async) to the below. If I remove the
results.forEach…
and instead just doconsole.log(results)
then typewiz works fine. So I think it due to having the nested arrow statements somehow?On running:
typewiz-node src/app.ts
Error:
The text was updated successfully, but these errors were encountered: