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

JS: 'variable' is declared but its value is never read. #51814

Closed
pocesar opened this issue Jun 14, 2018 · 13 comments
Closed

JS: 'variable' is declared but its value is never read. #51814

pocesar opened this issue Jun 14, 2018 · 13 comments
Assignees
Labels
info-needed Issue requires more information from poster *not-reproducible Issue cannot be reproduced by VS Code Team member as described

Comments

@pocesar
Copy link

pocesar commented Jun 14, 2018

Version: 1.25.0-insider
Commit: 583f1e4
Date: 2018-06-13T05:18:10.709Z
Electron: 2.0.2
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Seems like a regression, the editor can't decide if passing the variable to a function counts as "read" it seems

image

const glob = require('glob')
const expressWinston = require('express-winston')
const bodyParser = require('body-parser')
const logger = require('./logger')
const config = require('./config')
const helpers = require('./helpers')
const cookieParser = require('cookie-parser')
const jsonwebtoken = require('jsonwebtoken')
const serveStatic = require('serve-static')

image

image

Steps to Reproduce:

express middleware in this example

  1. Create a const something = (req, res, next) => { next() }
  2. Assign it to the express application using app.use(something)

Does this issue occur when all extensions are disabled?: Yes

@pocesar
Copy link
Author

pocesar commented Jun 14, 2018

not sure if it's relevant, but Output for Typescript shows:

[Info  - 11:35:35 PM] Started TSServer
[Error  - 11:43:31 PM] 'getApplicableRefactors' request failed with error.
Error processing request. Debug Failure. False expression.
Error: Debug Failure. False expression.
    at getJSDocTags (C:\nodejs\node_modules\typescript\lib\tsserver.js:11705:22)
    at getFirstJSDocTag (C:\nodejs\node_modules\typescript\lib\tsserver.js:11712:24)
    at Object.getJSDocType (C:\nodejs\node_modules\typescript\lib\tsserver.js:11689:19)
    at getContextualSignature (C:\nodejs\node_modules\typescript\lib\tsserver.js:35577:32)
    at checkFunctionExpressionOrObjectLiteralMethod (C:\nodejs\node_modules\typescript\lib\tsserver.js:38366:43)
    at checkExpressionWorker (C:\nodejs\node_modules\typescript\lib\tsserver.js:39292:28)
    at checkExpression (C:\nodejs\node_modules\typescript\lib\tsserver.js:39225:42)
    at checkExpressionCached (C:\nodejs\node_modules\typescript\lib\tsserver.js:39111:38)
    at getWidenedTypeFromJSSpecialPropertyDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:26652:46)
    at getTypeOfVariableOrParameterOrProperty (C:\nodejs\node_modules\typescript\lib\tsserver.js:26887:28)
    at getTypeOfSymbol (C:\nodejs\node_modules\typescript\lib\tsserver.js:27103:24)
    at checkPropertyAccessExpressionOrQualifiedName (C:\nodejs\node_modules\typescript\lib\tsserver.js:36627:53)
    at checkPropertyAccessExpression (C:\nodejs\node_modules\typescript\lib\tsserver.js:36582:20)
    at getSymbolOfEntityNameOrPropertyAccessExpression (C:\nodejs\node_modules\typescript\lib\tsserver.js:43271:25)
    at getSymbolAtLocation (C:\nodejs\node_modules\typescript\lib\tsserver.js:43324:28)
    at Object.getSymbolAtLocation (C:\nodejs\node_modules\typescript\lib\tsserver.js:22968:31)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88756:35)
    at visitNode (C:\nodejs\node_modules\typescript\lib\tsserver.js:13176:24)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13347:24)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNode (C:\nodejs\node_modules\typescript\lib\tsserver.js:13176:24)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13248:21)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNodes (C:\nodejs\node_modules\typescript\lib\tsserver.js:13185:30)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13338:24)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNodes (C:\nodejs\node_modules\typescript\lib\tsserver.js:13185:30)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13349:21)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNodes (C:\nodejs\node_modules\typescript\lib\tsserver.js:13185:30)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13349:21)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNode (C:\nodejs\node_modules\typescript\lib\tsserver.js:13176:24)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13406:24)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNodes (C:\nodejs\node_modules\typescript\lib\tsserver.js:13185:30)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13395:24)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNode (C:\nodejs\node_modules\typescript\lib\tsserver.js:13176:24)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13290:21)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNode (C:\nodejs\node_modules\typescript\lib\tsserver.js:13176:24)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13377:21)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNode (C:\nodejs\node_modules\typescript\lib\tsserver.js:13176:24)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13406:24)
    at checkForUsedDeclarations (C:\nodejs\node_modules\typescript\lib\tsserver.js:88772:24)
    at visitNodes (C:\nodejs\node_modules\typescript\lib\tsserver.js:13185:30)
    at Object.forEachChild (C:\nodejs\node_modules\typescript\lib\tsserver.js:13397:24)
    at collectReadsAndWrites (C:\nodejs\node_modules\typescript\lib\tsserver.js:88585:24)
    at getPossibleExtractionsWorker (C:\nodejs\node_modules\typescript\lib\tsserver.js:88029:38)
    at getPossibleExtractions (C:\nodejs\node_modules\typescript\lib\tsserver.js:87986:26)
    at Object.getAvailableActions (C:\nodejs\node_modules\typescript\lib\tsserver.js:87582:35)
    at C:\nodejs\node_modules\typescript\lib\tsserver.js:84109:128
    at getIterator (C:\nodejs\node_modules\typescript\lib\tsserver.js:1856:23)
    at Object.next (C:\nodejs\node_modules\typescript\lib\tsserver.js:1851:35)
    at Object.arrayFrom (C:\nodejs\node_modules\typescript\lib\tsserver.js:2407:32)
    at Object.getApplicableRefactors (C:\nodejs\node_modules\typescript\lib\tsserver.js:84108:23)
    at Object.getApplicableRefactors (C:\nodejs\node_modules\typescript\lib\tsserver.js:91429:32)
    at IOSession.Session.getApplicableRefactors (C:\nodejs\node_modules\typescript\lib\tsserver.js:97919:53)
    at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (C:\nodejs\node_modules\typescript\lib\tsserver.js:96811:61)
    at C:\nodejs\node_modules\typescript\lib\tsserver.js:98126:88
    at IOSession.Session.executeWithRequestId (C:\nodejs\node_modules\typescript\lib\tsserver.js:98117:28)
    at IOSession.Session.executeCommand (C:\nodejs\node_modules\typescript\lib\tsserver.js:98126:33)
    at IOSession.Session.onMessage (C:\nodejs\node_modules\typescript\lib\tsserver.js:98146:35)
    at Interface.<anonymous> (C:\nodejs\node_modules\typescript\lib\tsserver.js:99377:27)
    at emitOne (events.js:116:13)
    at Interface.emit (events.js:211:7)
    at Interface._onLine (readline.js:282:10)
    at Interface._normalWrite (readline.js:424:12)
    at Socket.ondata (readline.js:141:10)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

@weinand weinand assigned mjbvz and unassigned weinand Jun 14, 2018
@mjbvz
Copy link
Collaborator

mjbvz commented Jun 14, 2018

Possible duplicate of microsoft/TypeScript#24963

Please test this in the latest VS Code insiders build to see if it was already fixed

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Jun 14, 2018
@pocesar
Copy link
Author

pocesar commented Jun 14, 2018

@mjbvz same issue (the OP, not the TSServer error)

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 14, 2018

Thanks. Can you please try upgrading your workspace to use typescript@next by following these instructions: https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions

@pocesar
Copy link
Author

pocesar commented Jun 15, 2018

already using typescript@next, I always use it alongside with vscode insiders

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 15, 2018

Can you please share a small, complete example project

@writesandy
Copy link

writesandy commented Jun 17, 2018

I'm having the same problem - anyone find a solution? When I type in the code below cherrio, db, PORT, app all say , 'is declared, but value is never read'.

const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");

//Our scraping tools
const cheerio = require("cheerio");

//Require all models
const db = require("./models");

const PORT = 3000;

// Initialize Express
const app = express();

// Configure middleware

// request for logging requests

@JessePreiner
Copy link

Not 100% sure it's related, if not i'll open up a new issue. There are a few cases of variables reported as not being used when they are, this is one example with code 1.24.1
image

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 19, 2018

@writesandy Please share a complete example. Those variable really not not used anywhere in the current example

@ManyouRisms Do you access .apiUrl anywhere? If not, marked it as unused is correct and you should remove private

@JessePreiner
Copy link

After injecting it I assign it directly to a private _apiUrl which I then use throughout the code. That in itself I would assume would classify as 'being used', because if i was to remove the declaration of apiUrl all together, the build would break because it is indeed getting used in the constructor.

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 20, 2018

@ManyouRisms with private apiUrl you now have two properties: this.apiUrl and this._apiUrl. You should remove private from private apiUrl in the constructor if you are not using it as a property

@BridgeAR
Copy link

Here another example that fails:

screenshot from 2018-06-24 13-49-08

In this case the return statement is "somewhat valid" in Node.js since all functions are wrapped in a function implicitly and I believe that is the issue for TS in this context (it just did not expect a return without being wrapped in a function).

@mjbvz
Copy link
Collaborator

mjbvz commented Jun 25, 2018

Closing as we do not have enough information to investigate the original issue

Please open new issues for other problems around unused variables

@mjbvz mjbvz closed this as completed Jun 25, 2018
@mjbvz mjbvz added the *not-reproducible Issue cannot be reproduced by VS Code Team member as described label Jun 25, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster *not-reproducible Issue cannot be reproduced by VS Code Team member as described
Projects
None yet
Development

No branches or pull requests

6 participants