Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[quotemark] backtick breaks old typescript #4645

Closed
ericbf opened this issue Apr 7, 2019 · 3 comments · Fixed by #4642
Closed

[quotemark] backtick breaks old typescript #4645

ericbf opened this issue Apr 7, 2019 · 3 comments · Fixed by #4642

Comments

@ericbf
Copy link
Contributor

ericbf commented Apr 7, 2019

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

@JoshuaKGoldberg
Copy link
Contributor

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.

@ericbf
Copy link
Contributor Author

ericbf commented Apr 7, 2019

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

@JoshuaKGoldberg
Copy link
Contributor

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

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

Successfully merging a pull request may close this issue.

2 participants