Tslint: Optional Chaining not supported

Created on 26 Nov 2018  Â·  10Comments  Â·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.11.0
  • __TypeScript version__: 3.1.6
  • __Running TSLint via__: Cli
const extractorData = {
    name: hostname,
    extractFrom: {
     dataType: data.extractFrom,
     urlList: data.urlList ? data.urlList : [],
     parentExtractor: {
      extractor: data?.extractor,
      runParentExtractorFirst: data?.runParentExtractorFirst,
      urlColumn: data?.urlColumn
     }
    },
    sendEmail: data.sendEmail
   };

with tslint.json configuration:

{
  "rules": {
    "class-name": true,
    "comment-format": [true, "check-space"],
    "indent": [true, "spaces"],
    "one-line": [true, "check-open-brace", "check-whitespace"],
    "no-var-keyword": true,
    "quotemark": [true, "double", "avoid-escape"],
    "semicolon": [true, "always", "ignore-bound-class-methods"],
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-module",
      "check-separator",
      "check-type"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      },
      {
        "call-signature": "onespace",
        "index-signature": "onespace",
        "parameter": "onespace",
        "property-declaration": "onespace",
        "variable-declaration": "onespace"
      }
    ],
    "no-internal-module": true,
    "no-trailing-whitespace": true,
    "no-null-keyword": true,
    "prefer-const": true,
    "jsdoc-format": true
  }
}

Actual behavior

The following stack traces are output:

/usr/local/lib/node_modules/ts-node/src/index.ts:261
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/utils/Scraper/web/extractor/ExtractorHandler.ts(16,23): error TS1109: Expression expected.
src/utils/Scraper/web/extractor/ExtractorHandler.ts(16,33): error TS1005: ':' expected.
src/utils/Scraper/web/extractor/ExtractorHandler.ts(17,37): error TS1109: Expression expected.
src/utils/Scraper/web/extractor/ExtractorHandler.ts(17,61): error TS1005: ':' expected.
src/utils/Scraper/web/extractor/ExtractorHandler.ts(18,23): error TS1109: Expression expected.
src/utils/Scraper/web/extractor/ExtractorHandler.ts(19,6): error TS1005: ':' expected.

    at createTSError (/usr/local/lib/node_modules/ts-node/src/index.ts:261:12)
    at getOutput (/usr/local/lib/node_modules/ts-node/src/index.ts:367:40)
    at Object.compile (/usr/local/lib/node_modules/ts-node/src/index.ts:558:11)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:439:43)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/alihesari/projects/scraper/server/src/utils/Scraper/web/WebCrawler.ts:1:1)
    at Module._compile (module.js:652:30)
    at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:439:23)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:442:12)
[nodemon] app crashed - waiting for file changes before starting...

Expected behavior

I would expect the Optional Chaning supported.

External

Most helpful comment

@JoshuaKGoldberg Now would be that time :-)

All 10 comments

Hi @alihesari! Your issue is with TypeScript the language, not TSLint the linter.

TypeScript does not yet support optional chaining because the proposal to add it to JavaScript has not reached the stage where it's guaranteed to not change significantly. See https://github.com/Microsoft/TypeScript/issues/16.

@JoshuaKGoldberg Now would be that time :-)

SO EXCITED!!!!

Yeah just ran into this issue now using the TS 3.7 beta
image

@kdawgwilk TSLint uses TypeScript for syntax parsing, so that error isn't on the TSLint side. Check which version of TypeScript your linter extension is using - it's likely in the node_modules/ of its TSLint installation.

Also, not-so-subtle link to #4534: TSLint is gonna be dead soon!

Oh that’s good to know i might be able to force the right version of TS prettier is using, thanks! I sure hope TSLint is not going to be dead soon, eslint checking TS code is like 10x slower right now 😞

Yeah just ran into this issue now using the TS 3.7 beta
image

do you find some way to resolve it ?

Please update the initial description of this issue and reopen this issue
_Or open a new issue_

@JoshuaKGoldberg is there a way how to tell tslint what typescript version should use? i downloaded latest tslint and in packagejson is old version of typescript.

Try also installing and saving the latest version of TypeScript?

Anyway, this issue isn't really the right place to ask for support - try StackOverflow or Gitter, filing a new issue if you think there's a bug in TSLint. Best of luck!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

denkomanceski picture denkomanceski  Â·  3Comments

Ne-Ne picture Ne-Ne  Â·  3Comments

SwintDC picture SwintDC  Â·  3Comments

ypresto picture ypresto  Â·  3Comments