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

Incorrect errors when adding this parameter to functions #1393

Closed
olee opened this issue Jul 12, 2016 · 8 comments
Closed

Incorrect errors when adding this parameter to functions #1393

olee opened this issue Jul 12, 2016 · 8 comments

Comments

@olee
Copy link

olee commented Jul 12, 2016

Bug Report

  • TSLint version: (unknown - tslint used by Atom plugin linter-tslint)
  • TypeScript version: latest
  • Running TSLint via: Atom

TypeScript code being linted

function cloneEntity(this: IEntity) {
    var result = Object.create(Object.getPrototypeOf(this));
    Object.keys(this).filter(key => !key.startsWith('$') && filteredEntityProperties.indexOf(key) < 0).forEach((key) => {
        result[key] = angular.copy(this[key]);
    });
    return result;
}

Actual behavior

The following errors are show (in Atom)

no-unused-expression - expected an assignment or function callat line 22 col 22
no-unused-expression - expected an assignment or function callat line 22 col 28
semicolon - missing semicolonat line 22 col 26
semicolon - missing semicolonat line 22 col 35

Expected behavior

No error shown

@adidahiya
Copy link
Contributor

Can you please dig in and find the tslint & typescript version actually in use? By "latest" do you mean v2.0? I think this has to do with some new syntax introduced recently into the language.

@olee
Copy link
Author

olee commented Jul 15, 2016

The definition of a this type in functions was added in this PR and it is part of Typescript 2.0
I think tslint probably just doesn't support it yet.

@olee
Copy link
Author

olee commented Aug 4, 2016

Do you still need more information?
I don't really know what else I could provide you.
It would be really nice if tslint could handle those cases because right now I get warnings everywhere...

@adidahiya
Copy link
Contributor

@olee have you tryied using tslint@next? See this bit of the readme about using latest versions of the compiler: https://github.com/palantir/tslint#peer-dependencies

@olee
Copy link
Author

olee commented Aug 6, 2016

How would I go about using tslint@next in Atom-typescript so I can try it?
Does someone know that?

@jkillian
Copy link
Contributor

jkillian commented Aug 7, 2016

You could try npm install -g tslint@next and try running it on your code via the CLI. If you can duplicate the bug via the CLI, it's definitely a TSLint bug

@olee
Copy link
Author

olee commented Aug 7, 2016

Indeed, using tslint together with typescript@next seems to work properly with this test code:

function formatShortDate(this: Date) {
    return `${this.getFullYear()}-${this.getMonth()}-${this.getDate()}`;
}

Date.prototype.formatShortDate = formatShortDate;

console.log(new Date().formatShortDate());

Now I just need to figure out how to get atom-tslint to use typescript@next (or tslint@next) as well...

EDIT: Seems that linter-tslint allows using different tslint version, however right now it crashes when loading new typescript version so that needs to be fixed first: AtomLinter/linter-tslint#104

@jkillian
Copy link
Contributor

jkillian commented Aug 8, 2016

Glad it's not a TSLInt bug! Going to close this issue, but feel free to continue discussion here if needed

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

No branches or pull requests

3 participants