Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [ban-types] rework default options#848
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@bradzacher! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint |
I'm not sure if it makes sense to include Also, as mentioned in#842, I'm not sure if fixing the |
bradzacher commentedAug 13, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
updated code and OP description. LMK your thoughts on this.
This is not a correct statement. The fact that they were all "use camelCase instead of PascalCase" was purely coincidental. |
It's definitely an improvement, although I'm still not 100% sure about
I meant that thedefaults have always been about object wrappers, that's not to say that other objects cannot be used, just that it would be a (breaking, BTW) change to how things have been for quite a while now, and as I said, developers can always add this type to their configurations if they have no use for it in their codebases. |
I'm inclined to agree that this is a breaking change, so I've tagged it for v3 (which won't be miles away, we won't leave as big of a gap as we did between 1 and 2) |
eole1712 commentedNov 6, 2019
@JamesHenry Maybe until then we can give a way to disable the default behaviour for Object type ? Should I do a PR for this? |
Uh oh!
There was an error while loading.Please reload this page.
Have you considered adding
(no fixers) |
|
bradzacher commentedDec 28, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yeah I haven't revisited this in a while, but both of those seem reasonable. For context of the types here: I really want the default config to reflect things you shouldn't use 99% of the time, because the 1% is easily covered by disable comments, with a supporting comment explaining why it's a reasonable usage. I would definitely argue that This is why For The problem is that I added a fixer with the original defaults, and I think there shouldn't be one for these types. "Basic" users probably want the fixer, as they meant an object type, but "advanced" users know what the type means, so they use it "correctly", so the fixer breaks their code. A very clear message explaining exactly what the types do is the best approach for them (same for functiontest_Record(obj:Record<string,unknown>){obj.foo.toString();// ✅ Expected Error - obj.foo is of type unknownif('foo'inobj){obj.foo.toString();// ✅ Expected Error - obj.foo is of type unknown}if(typeofobj.foo==='object'&&obj.foo){obj.foo.toString();// ✅ No Error}if(objinstanceofDate){obj.getDate();// ✅ No Error}}functiontest_object(obj:object){obj.foo.toString();// ✅ Expected Error - Property 'foo' does not exist on type 'object'.if('foo'inobj){obj.foo.toString();// ❌ Weird error - Property 'foo' does not exist on type 'object'.}if('foo'inobj&&typeofobj.foo==='object'&&obj.foo){// ❌ Unexpected Error - Property 'foo' does not exist on type 'object'.obj.foo.toString();// ❌ Unexpected error - same}}functiontest_Object(obj:Object){obj.foo.toString();// ✅ Expected Errorif('foo'inobj){obj.foo.toString();// ❌ Weird error - Property 'foo' does not exist on type 'object'.}if('foo'inobj&&typeofobj.foo==='object'&&obj.foo){// ❌ Unexpected Error - Property 'foo' does not exist on type 'object'.obj.foo.toString();// ❌ Unexpected error - same}}test_Record({});// ✅ Expected No Errortest_object({});// ✅ Expected No Errortest_Object({});// ✅ Expected No Errortest_Record(1);// ✅ Expected Errortest_object(1);// ✅ Expected Errortest_Object(1);// ❌ Unexpected No Errortest_Record(true);// ✅ Expected Errortest_object(true);// ✅ Expected Errortest_Object(true);// ❌ Unexpected No Errortest_Record(null);// ✅ Expected Errortest_object(null);// ✅ Expected Errortest_Object(null);// ✅ Expected Errortest_Record(()=>{});// ✅ Expected Errortest_object(()=>{});// ❌ Unexpected No Errortest_Object(()=>{});// ❌ Unexpected No Error |
Did you mean I'm still a bit unsure about
... I assume that you mean: (objasDate).getDate(); ... but you can also use functiontest(obj:object){if(objinstanceofDate){obj.getDate();}elseif(objinstanceofLocation){obj.hash;}} |
Sorry, I just realised I messed up my example because TS only reported one error per expression. I've updated it so it's correct. But yes,
Instance of is definitely one way to refine it, but that only works when you have a well defined class structure, etc. But then if you're expecting a What I'm talking about expressly is the "I accept any object; anything that can use the string indexer and works correctly with |
I think the main difference between the two is that with It would be interesting to see actual use cases of both types.
It was just a contrived example to show the usage of |
Retsam commentedDec 29, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Overall, personally, I wouldn't ban
functionnoviceCode(x:object){return(xasany).a+(xasany).b;} And The narrowing thing is a shame, but In fact, it's specifically because I imagine this issue will get fixed eventually, (which would mean fixing And using And in general, banning The new (unreleased)handbook section on
As I mentioned above, it's rare that I think |
Which is the point I was making. 99.9% of the time, you don't want to use it, and the vast majority of codebases won't want to use it. IMO that makes it a great candidate for banning by default. I agree though, that a fixer was the wrong approach. For both |
203b203
to0aa09e1
CompareNote: I have updated the PR based on feedback. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
codecovbot commentedJan 13, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## v3 #848 +/- ##==========================================- Coverage 93.91% 93.87% -0.04%========================================== Files 171 172 +1 Lines 7789 7804 +15 Branches 2240 2239 -1 ==========================================+ Hits 7315 7326 +11- Misses 217 221 +4 Partials 257 257
|
Uh oh!
There was an error while loading.Please reload this page.
BREAKING CHANGE:
Updated the config based on feedback:
object
andObject
{}
Function
Fixes#842