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

Bad inferences with error TS2365 #14695

Closed
ghost opened this issue Mar 16, 2017 · 3 comments
Closed

Bad inferences with error TS2365 #14695

ghost opened this issue Mar 16, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@ghost
Copy link

ghost commented Mar 16, 2017

TypeScript Version: 2.2.1

Code

class Foo {
  _elements: string[];

  constructor(input: string) {
    this._elements = input.split("");
  }

  get top(): string {
    return (this._elements.length > 0) ?
      this._elements[this._elements.length - 1] :
      "";
  }

  strip(): number {
    if (this.top == "$") {
      this._elements.pop(); // $
      let count = 0;
      while (this.top != "^") { // XXX TS2365
        ++count;
        this._elements.pop();
      }
      this._elements.pop(); // ^
      return count;
    }

    return 0;
  }
}

let f = new Foo("ba^z$");
console.log(f.strip());

Expected behavior:

Clean compilation, with no errors or warnings.

Actual behavior:

foo.ts(18,14): error TS2365: Operator '!=' cannot be applied to types '"$"' and '"^"'.

@ghost
Copy link
Author

ghost commented Mar 16, 2017

This may be related to issue #12794, or maybe not, but even if so, it looks like there's a lot of noise and casted aspersions wrt the testcases in that issue, rather than engineering.

@gcnew
Copy link
Contributor

gcnew commented Mar 16, 2017

It is. See #9998 (comment)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 17, 2017
@RyanCavanaugh
Copy link
Member

Duplicate #13904 / we don't keep open issues from 👻 s, too spooky

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants