jscodeshift icon indicating copy to clipboard operation
jscodeshift copied to clipboard

Why can't I specify `typeParameters` to a `CallExpression`?

Open lyleunderwood opened this issue 6 years ago • 3 comments

I can't get the following code to add type parameters to my CallExpression in any of the parsers I've tried (flow and babylon7):

  const myExpression = j.callExpression(
    j.identifier('withTheme'), 
    [j.identifier('Thing')],
    j.typeParameterInstantiation([
      j.genericTypeAnnotation(j.identifier('Props'), null),
    ])
  );

AST Explorer

Forgive me if I've entered this issue in the wrong place, I don't yet really follow how the jscodeshift ecosystem fits together.

Here it looks like the callExpression builder function is being decorated with a third argument for type parameters, but if I just pass junk into that argument there is no type error.

lyleunderwood avatar Jul 01 '19 11:07 lyleunderwood

Similar issue with TS parser. typeParameters are wiped out from the call expression on toSource() call.

valerybugakov avatar Oct 30 '19 07:10 valerybugakov

It seems that it's an issue of recast https://github.com/benjamn/recast/issues/266

valerybugakov avatar Oct 30 '19 07:10 valerybugakov

This issue is resolved in the latest versions of recast, https://github.com/benjamn/recast/pull/613. Version is even updated in jscodeshift, it's just not published to the registry.

valerybugakov avatar Oct 30 '19 08:10 valerybugakov