question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--noImplicitThis error is inconsistent

See original GitHub issue

TypeScript Version: 3.0.0-dev.20180707

Code

declare function f(a: any): void;
f(function() {
	this.m();
});

f({
	callback: function() {
		this.m();
	}
});

Expected behavior:

With --noImplicitThis, errors in both cases or neither case.

Actual behavior:

Only error in the first case.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andy-mscommented, Oct 12, 2018

That situation seems even worse because you never declared an any anywhere. But it would be likely to be fixed when this one is, so I’ll make it a part of this issue.

class x {
    public variable: number = 0;
    public x() {
        const c = [];
        c.push({
            xxx () {
                console.log(this.variable); // Should error
            }
        });
    }
}

A workaround is to declare an explicit type for c, as in const c: Array<{ xxx(): void }> = [];.

0reactions
andy-mscommented, Oct 13, 2018

Array.push should have a parameter of type T where T is the array’s element type. With --noImplicitAny enabled, if the array didn’t have a declared type we should be inferring one – not just making it any.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent implicitly has an 'any' type error - Stack Overflow
I'm using TypeScript Version 2.3.2. I experienced a transpile error with noImplicitAny option. I feel that the erro is something inconsistent.
Read more >
TSConfig Reference - Docs on every TSConfig option
No Implicit This - noImplicitThis. Raise error on 'this' expressions with an implied 'any' type. For example, the class below returns a function...
Read more >
TypeScript Tutorial => Configuration for fewer programming ...
Learn TypeScript - Configuration for fewer programming errors. ... Disallow inconsistently-cased references to the same file.
Read more >
How To Configure tsconfig.json: TypeScript Strict options
You need to set some type to avoid this TypeScript error. ... TypeScript Strict options in tsconfig.json: noImplicitThis.
Read more >
Understanding TypeScript Configuration Options
Types of parameters 'age' and 'age' are incompatible. ... When noImplicitThis is enabled, TypeScript will raise an error when this ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found