Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

no-unnecessary-local-variable throws an error after upgrade to TS3 #485

Closed
YouHusam opened this issue Aug 8, 2018 · 3 comments
Closed
Labels
Resolution: Fixed Hooray! Status: Needs More Info The issue, as stated, needs additional clarification and context. Type: Bug
Milestone

Comments

@YouHusam
Copy link

YouHusam commented Aug 8, 2018

After upgrade to Typescript 3, I get the following warning in tslint for multiple files.

The 'no-unnecessary-local-variable' rule threw an error in 'path/to/file.tsx':
TypeError: ts.unescapeIdentifier is not a function
    at Object.getIdentifierText (/Users/youho01/projects/v3/node_modules/tsutils/util/util.js:872:15)
    at UsageWalker._handleDeclaration (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:667:44)
    at cb (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:577:27)
    at visitNode (/Users/youho01/projects/v3/node_modules/typescript/lib/typescript.js:15123:24)
    at Object.forEachChild (/Users/youho01/projects/v3/node_modules/typescript/lib/typescript.js:15466:21)
    at cb (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:596:23)
    at visitNodes (/Users/youho01/projects/v3/node_modules/typescript/lib/typescript.js:15132:30)
    at Object.forEachChild (/Users/youho01/projects/v3/node_modules/typescript/lib/typescript.js:15358:24)
    at UsageWalker.getUsage (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:611:12)
    at Object.collectVariableUsage (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:126:30)

The deprecated functions escapeIdentifier and unescapeIdentifier have been removed. Due to changing how the identifier name API worked in general, they have been identity functions for a few releases, so if you need your code to behave the same way, simply removing the calls should be sufficient. Alternatively, the typesafe escapeLeadingUnderscores and unescapeLeadingUnderscores should be used if the types indicate they are required (as they are used to convert to or from branded __String and string types).

ref: https://github.com/Microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-30

Node version: 10.4.0
NPM version: 6.1.0
OS: MacOS 10.13.6
Typescript: 3.0.1

@JoshuaKGoldberg
Copy link

The top of the error stack is interesting:

Object.getIdentifierText (/Users/youho01/projects/v3/node_modules/tsutils/util/util.js:872:15)
    at UsageWalker._handleDeclaration (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:667:44)
    at cb (/Users/youho01/projects/v3/node_modules/tsutils/util/usage.js:577:27)

@YouHusam what version of tsutils do you have? (as specified in /Users/youho01/projects/v3/node_modules/tsutils/package.json)

tsutils has since updated to no longer use ts.unescapeIdentifier. I wonder if we tslint-microsoft-contrib should have a new major version release to explicitly drop support for versions of tsutils that still use that?

@JoshuaKGoldberg JoshuaKGoldberg added the Status: Needs More Info The issue, as stated, needs additional clarification and context. label Aug 8, 2018
@YouHusam
Copy link
Author

YouHusam commented Aug 9, 2018

According to the package.json: "version": "2.27.1"

@JoshuaKGoldberg
Copy link

JoshuaKGoldberg commented Aug 13, 2018

Funny, looks like you're exactly one minor patch version behind 2.27.2, which has a fix for that: ajafff/tsutils#71.

I'll bump the tsutils minimum version in the tslint-microsoft-contrib package and release this as a bug fix next version. Thanks for the bug report! 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Fixed Hooray! Status: Needs More Info The issue, as stated, needs additional clarification and context. Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants