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
[unbound-method] console methods are bound #1085
Comments
After looking into this a bit, I guess the proper way to resolve this would be changing types/node declare var console: NodeJS.GlobalConsole;
declare namespace NodeJS {
interface GlobalConsole extends Console {
Console: NodeJS.ConsoleConstructor;
log: OmitThisParameter<Console["log"]>;
error: OmitThisParameter<Console["error"]>;
// …
};
} except that this appears to require coordination with So probably special-casing the |
@bradzacher I'm keen to give this a go, but so far all I can come up with is doing something along the lines of
Which I don't think is the worst solution in the world, but I feel like I should be able to use the type information to get the actual type of Got any tips or pointers for me? (Mind you, that solution could actually be considered more error-prone, since unless you can confirm exactly where a type came from, it'd match any interface called |
@G-Rath, you might be able to do something similar to what I suggested for the
Though TBH I'm not sure if Maybe it's "good enough" to instead ensure that |
So close, and yet so far 😭 You're right that it doesn't work unless you include the I'll have a hunt around and see if I can figure out a cunning way around it, but otherwise I'll look at doing the good enough path 🤷♂ |
FYI I think there are a few other instances of this problem, e.g. @ab-pm I'm curious to hear more about how you would solve this by changing the types. log: OmitThisParameter<Console["log"]>; AFAICS, … so why would we need to omit it if it's not there to start with? |
Seems to be implicit because it's declared as a method on the |
IIUC, TypeScript does not automatically add When a method does have a class Foo {
bar(this: this) {}
}
declare const foo: Foo;
foo.bar.call(null); // error But this is not the case for console.log.call(null); // no error |
@OliverJAsh You must have more TS knowledge than me then :-) Notice however that I am not using
Only |
Also getting issues for Would require type-checking but it would be worth it IMHO. |
Would you have any pointers for this, such as an already existing rule that does this? Right now I'm going to aim for having something of a hardcoded array we can chuck things like "console", "Number", "String", etc into and then we can think about how to improve things longer term. |
I would think that you can do something along the lines of like:
It's not perfect, but I think that it's "good enough". |
Expected
The code should be accepted by the linter.
Actual
I'm getting an error, complaining that
.error
is an unbound method.I'm not sure how this should be fixed - changing the type declarations of the builtin types to no longer require a
this
argument? Or providing anexceptions
option in the rule configuration?Versions
@typescript-eslint/eslint-plugin
2.4.0
The text was updated successfully, but these errors were encountered: