Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating @babel/types breaks typings #169

Closed
gilbsgilbs opened this issue Sep 30, 2020 · 2 comments · Fixed by #210
Closed

Updating @babel/types breaks typings #169

gilbsgilbs opened this issue Sep 30, 2020 · 2 comments · Fixed by #210
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@gilbsgilbs
Copy link
Owner

gilbsgilbs commented Sep 30, 2020

Describe the bug

Upgrading @babel/types to 7.10.0+ breaks typings. For example:

function foo(path: NodePath) {
  if (nodePath.isMemberExpression()) {
    // nodePath used to be of type "NodePath<MemberExpression>" here.
    // But now is "NodePath<Node> & NodePath<MemberExpression>".

    // As a result, obj has a loose type: "NodePath<Node> | NodePath<Node>[]"
    // Used to be "NodePath<Expression>".
    const obj = path.get('object');

    // And then this breaks:
    obj.isIdentifier();
  }
}

Hard to figure out a proper fix and understand why this happens. The only workaround I found so far is too cumbersome to be acceptable:

function foo(path: NodePath) {
  if (nodePath.isMemberExpression()) {
    const obj = (path as NodePath<MemberExpression>).get('object');

    // now obj has expected type, we can do:
    obj.isIdentifier();
  }
}

Another problem:

function foo(path: NodePath<Node>) {}
function bar(expr: NodePath<CallExpression>) {
    // fails here
    //  ↓↓↓↓
    foo(expr);
}

Now fails with the following error:

Argument of type 'NodePath<CallExpression>' is not assignable to parameter of type 'NodePath<Node>'.
  Type 'Node' is not assignable to type 'CallExpression'.
    Type 'AnyTypeAnnotation' is missing the following properties from type 'CallExpression': callee, arguments, optional, typeArguments, typeParametersts(2345)

Waiting for a proper fix, #170 pinned @babel/types to the latest version that works: 7.9.6. Starting at 7.10.0 the breaking change occurs 🤷‍♂️ .

How to reproduce

  • remove yarn.lock and node_modules
  • upgrade all the dependencies
  • yarn run types

Expected behavior

Types should be strong and not break.

What actually happens

Lot of typing errors, mostly related to the aforementioned issue. For example:

src/extractors/withTranslationHOC.ts:293:62 - error TS2345: Argument of type 'NodePath<Node> | NodePath<Node>[]' is not assignable to parameter of type 'NodePath<Node>'.
  Type 'NodePath<Node>[]' is not assignable to type 'NodePath<Node>'.

293         result.push(...findTFunctionCallsFromPropsAssignment(id));
                                                                 ~~

Your environment

irrelevant

Additional context

None

@xDisfigure
Copy link
Contributor

taking a look at it

@gilbsgilbs
Copy link
Owner Author

Wow, thanks mate. FYI, I've asked the question on Babel's slack channel. I don't have a lot of hopes, but maybe it's a known issue 🤷 .

@gilbsgilbs gilbsgilbs changed the title Updating dependencies breaks typings Updating @babel/types breaks typings Oct 1, 2020
@gilbsgilbs gilbsgilbs added bug Something isn't working help wanted Extra attention is needed labels Oct 1, 2020
@gilbsgilbs gilbsgilbs pinned this issue Oct 1, 2020
@gilbsgilbs gilbsgilbs unpinned this issue May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants