Skip to content

no-unused: Cannot read property 'exported' of undefined #81

@astorije

Description

@astorije

When run against this code:

declare global {
  namespace jest {
    interface Matchers<R> {
      toEqualSomething(argument: string): object;
    }
  }
}

The linter produces the following error:

The 'no-unused' rule threw an error in '.../test/foo.ts':
TypeError: Cannot read property 'exported' of undefined
    at typeParameterMayBeRequired (.../node_modules/tslint-consistent-codestyle/rules/noUnusedRule.js:238:31)
    at isExcluded (.../node_modules/tslint-consistent-codestyle/rules/noUnusedRule.js:192:60)
    at .../node_modules/tslint-consistent-codestyle/rules/noUnusedRule.js:38:17
    at Map.forEach (<anonymous>)
    at UnusedWalker.walk (.../node_modules/tslint-consistent-codestyle/rules/noUnusedRule.js:37:15)
    at Rule.AbstractRule.applyWithWalker (.../node_modules/tslint/lib/language/rule/abstractRule.js:31:16)
    at Rule.apply (.../node_modules/tslint-consistent-codestyle/rules/noUnusedRule.js:18:21)
    at Linter.applyRule (.../node_modules/tslint/lib/linter.js:197:29)
    at .../node_modules/tslint/lib/linter.js:139:85
    at Object.flatMap (.../node_modules/tslint/lib/utils.js:151:29)

It seems like when I remove <R> from Matchers<R>, the linter is happy again. However, while extending Jest with custom matchers, one has to use precisely Matchers<R> (i.e. it can't be Matchers, Matchers<T>, Matchers<void>, etc.).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions