Tslint: [quotemark] backtick breaks old typescript

Created on 7 Apr 2019  ·  3Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.15.0
  • __TypeScript version__: 2.4.x
  • __Running TSLint via__: Atom

TypeScript code being linted

declare let v: string | number

if (typeof v === "string") {
    v.substring(1)
}

// and

let obj: {
    key: "literal"
}

with tslint.json configuration:

{
    "rules": {
        "quotemark": [true, "backtick"]
    }
}

Actual behavior

Quotes are flagged (and changed to backticks with --fix)

Expected behavior

The quotes remain as they are, because this version of TS does not narrow the type of v when using typeof with a backtick string, and does not compiler at all when using a backtick string as a literal type

Accepting PRs Bug

All 3 comments

Quoting @ericbf from #4642:

Typescript below the listed version fails compilation (or otherwise misbehaves) when backticks are used in some places where it succeeds in future versions. For instance, typeof str === `string`​ does not narrow the type of str in TS versions below 2.7.1, causing compilation errors if you try to use it as a string later. In the other cases, older TS throws errors where NoSubstitutionLiterals are used instead of single/double quoted strings, but works fine in above 2.7.1; rather than cripple the rule to support order versions, I split it up.

See the typeof issue here. Its milestone was 2.7 (hence the split in this PR).
And here's the issue for backticks strings as types. This one was 2.6, but rather than doing multiple splits, I just did one at 2.7.

Weird – GitHub originally didn't save the issue info 🤷🏻‍♂️

👻 spooky! CircleCI is also being flaky today...

Was this page helpful?
0 / 5 - 0 ratings