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

[explicit-module-boundary-types] allowTypedFunctionExpressions no longer applies to arguments #1552

Closed
G-Rath opened this issue Jan 31, 2020 · 1 comment · Fixed by #1553
Closed
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Jan 31, 2020

Repro

Here's the repo itself: https://github.com/G-Rath/terraport/blob/master/src/formatter/ensurers.ts#L10

{
  "rules": {
    '@typescript-eslint/explicit-module-boundary-types': [
      'error',
      {
        allowTypedFunctionExpressions: true
      }
    ],
  }
}
export type Ensurer = (blocks: TFBlock[]) => TFBlock[];

export const myEnsurer: Ensurer = blocks => {
  return blocks;
};

Expected Result
blocks should not require a type, due to the type annotation on the variable.

Actual Result

ESLint: Argument 'blocks' should be typed.(@typescript-eslint/explicit-module-boundary-types)

Additional Info

Overall, explicit-module-boundary-types seems to have jumped in noise, as it's now erroring on a lot of my code.

For example:

export const ensureLabelsHaveLeadingSpace: Ensurer = blocks =>
  walkNodes(blocks, {
    Label: node => {
      node.surroundingText.leadingOuterText = ensureTextStartsWithTokens(
        node.surroundingText.leadingOuterText,
        [{ type: TokenType.Whitespace, content: ' ' }]
      );
    }
  });

I've now got block & node being marked as errors due to not being annotated with a type.
I've focused on block for now in this issue, but it seems like the behaviour is to now require a type definition for any function that is within a function that is exported.

Another example:

export const walkNodes = <TTheNode extends TFNode>(
  nodes: TTheNode[],
  listeners: NodeListeners
): TTheNode[] => nodes.map(node => walkNode(node, listeners));

Here node is marked as requiring a type, which I'd argue it shouldn't as it's not at the boundary - it's internal as an implementation detail.

It seems to me like #1490 might have had the opposite effect?

(It could be that I've misunderstood the intention of the rule, in which case I can turn this into a feature request I guess?)

Versions

package version
@typescript-eslint/eslint-plugin 2.18.1-alpha.5
@typescript-eslint/parser 2.18.1-alpha.5
TypeScript 3.7.5
ESLint 6.8.0
node 12.14.1
npm 6.13..6
@G-Rath G-Rath added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 31, 2020
@bradzacher bradzacher added bug Something isn't working has pr there is a PR raised to close this and removed triage Waiting for maintainers to take a look labels Jan 31, 2020
@bradzacher
Copy link
Member

Nah, this was my fault in #1493.
I refactored the code to reduce duplication and in doing so broke the fact that allowTypedFunctionExpressions works slightly differently in this rule.
Fixing it now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants