Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Rest parameter without type annotation in overload declaration cause null error #268

Closed
phuvo opened this issue May 12, 2017 · 2 comments
Closed

Comments

@phuvo
Copy link

phuvo commented May 12, 2017

What version of TypeScript are you using?
TypeScript 2.2

What version of typescript-eslint-parser are you using?
typescript-eslint-parser 2.1

What code were you trying to parse?

class World {
    batman(...args);
    batman(num: number) {}
}

// This also failed to parse
function batman(...args);
function batman(num: number) {}

What happened?

TypeError: Cannot read property 'type' of null
    at Referencer.visitFunction (U:\Documents\batman\node_modules\escope\lib\referencer.js:258:26)
    at Referencer.FunctionExpression (U:\Documents\batman\node_modules\escope\lib\referencer.js:569:18)
    at Referencer.Visitor.visit (U:\Documents\batman\node_modules\esrecurse\esrecurse.js:122:34)
    at Referencer.visitProperty (U:\Documents\batman\node_modules\escope\lib\referencer.js:297:18)
    at Referencer.MethodDefinition (U:\Documents\batman\node_modules\escope\lib\referencer.js:452:18)
    at Referencer.Visitor.visit (U:\Documents\batman\node_modules\esrecurse\esrecurse.js:122:34)
    at Referencer.Visitor.visitChildren (U:\Documents\batman\node_modules\esrecurse\esrecurse.js:101:38)
    at Referencer.Visitor.visit (U:\Documents\batman\node_modules\esrecurse\esrecurse.js:125:14)
    at Referencer.visitClass (U:\Documents\batman\node_modules\escope\lib\referencer.js:281:18)
    at Referencer.ClassDeclaration (U:\Documents\batman\node_modules\escope\lib\referencer.js:488:18)

Working code

The following code works:

class World {
    batman(...args: any[]);
    batman(num: number) {}
}

Appearantly, only batman(...args); (rest parameter without type annotation) cause the null error.

@soda0289
Copy link
Member

Thanks for the report.

This is a known issue. Unfortunately the scope anaylsis tool that eslint uses does not support empty body functions that can be found in typescript. This includes abstract methods, declared classes, and function overloads. This has since been fixed in ESLint v4 but there are still eslint rules that do not work with this syntax. We are working on getting this fixed as well.

More information can be found here: #253

@soda0289
Copy link
Member

Closing the issue in favor of #253

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants