-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ban-types] Should not ban {}
by default!
#2063
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
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
See comment at the end of this post: #2063 (comment) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We will not be removing This is the exact reason that the rule bans the The type This is obviously a huge type safety hole! For example - the following code is completely type-check valid, even though it might make no sense to be: interface AAA {
aaa: {};
}
const x: AAA = { aaa: true }; It's also important to note that empty interfaces behave in exactly the same way as the Unfortunately, there's no type in TS that means "an empty object". There are the following options for you: If you want a type that means "empty object"You can use a type similar to this type. type EmptyObject = Record<string, never>; // or {[k: string]: never}
const a: EmptyObject = { a: 1 }; // expect error
const b: EmptyObject = 1; // expect error
const c: EmptyObject = () => {}; // expect error
const d: EmptyObject = null; // expect error
const e: EmptyObject = undefined; // expect error
const f: EmptyObject = {}; // NO ERROR - as expected If you are using React, and you want to define
|
Uh oh!
There was an error while loading. Please reload this page.
A lot of type declaration is using
Type Aliases
, to let user fill in.For example a interface like this: (I got it from an official repo)
Sometimes detail is just an empty object! So it's good for me to write
Custom<{}>
, but V3 will throw an error ( not even a warning)In order to stop this error, I have to write
Custom<Record<never,never>>
, which is unneeded and a waste of time.So stop baning
{}
by default. May packages are holding certain objects for certain data, and to prevent theCannot read property 'xxx' of undefined
, they are usually initialize with{}
, so If I know that those fields are not containing any data, I should use{}
The text was updated successfully, but these errors were encountered: