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

@typescript-eslint/ban-types object not being handled. #1135

Closed
goldingdamien opened this issue Oct 24, 2019 · 3 comments
Closed

@typescript-eslint/ban-types object not being handled. #1135

goldingdamien opened this issue Oct 24, 2019 · 3 comments
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look

Comments

@goldingdamien
Copy link

Config is basically the same as this example but using "object" as well as other examples.
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md

function test(a: object) {
    console.log(a)
}

function test1(a: Object) {
    console.log(a)
}

Expected Result
Both object and Object show an error.
I'd actually expect any word regardless of case, defaults or anything else that may be the cause to work.

Actual Result
Don't use 'Object' as a type. Use Record<string, any> instead @typescript-eslint/ban-types

Additional Info
No errors. Debug output shows nothing relevant.

Versions

package version
@typescript-eslint/eslint-plugin 2.0.0
@typescript-eslint/parser 2.0.0
TypeScript 3.5.3
ESLint `6.1.0
node `12.1.0
npm 6.4.1
@goldingdamien goldingdamien added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 24, 2019
@bradzacher
Copy link
Member

See #848

The default configuration does not include handling for object.
If you want the rule to ban object, you must configure it yourself for now.


If you don't like the default suggestion for Object, you must configure it yourself for now.
The default configuration does include handling for Object, though when I added it, I didn't fully understand the scope of the Object type, so I completely misrepresented it.

@goldingdamien
Copy link
Author

Sorry, what do you mean by "configure it yourself"?
If I have a rule like below and only object is not showing an error, what should I do to get object to show an error?

 "@typescript-eslint/ban-types": ["error", {
            "types": {
                "a": null,
                "A": null,
                "object": null,
                "Object": null
             }
       }
]

Regards.

@bradzacher
Copy link
Member

Example, the default config:

{
types: {
String: {
message: 'Use string instead',
fixWith: 'string',
},
Boolean: {
message: 'Use boolean instead',
fixWith: 'boolean',
},
Number: {
message: 'Use number instead',
fixWith: 'number',
},
Object: {
message: 'Use Record<string, any> instead',
fixWith: 'Record<string, any>',
},
Symbol: {
message: 'Use symbol instead',
fixWith: 'symbol',
},
},
},

The docs you linked provide other examples of valid config:
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md#options

 "@typescript-eslint/ban-types": ["error", {
            "types": {
                "a": null,
                "A": null,
                "object": "do not use object",
                "Object": { 
                  message: 'Use Record<string, any> instead', 
                  fixWith: 'Record<string, any>',
               }
             }
       }
]

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look
Projects
None yet
Development

No branches or pull requests

2 participants