declare let j: unknown; let m = { ...(j as {}) };ESLint Config
module.exports = { parser: "@typescript-eslint/parser", rules: { "@typescript-eslint/ban-types": "error", }, };tsconfig
No response
Expected ResultFrom @RyanCavanaugh in #5018:
Now that
object
has been shipping in TS for several years, this seems like a safe suggestion in lieu ofRecord
's messy side effects
From @bradzacher in #5018 (comment):
The issue with
object
as a suggested replacement has always been that it's really hard use (microsoft/TypeScript#21732).
#21732 -> github.com/microsoft/TypeScript/pull/50666 has been shipped, so the major flaws mentioned should be gone now.
Proposal: let's suggest object
:
- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead. + If you want a type meaning "any object", you probably want `object` instead.
I'm unsure what to do about {}
. On the one hand:
Having typescript-eslint, out of the box, ban you from writing a type that TypeScript itself is inferring under totally normal operation, is awkward.
On the other hand, people do mistake it for "any object". 🤔
Actual ResultRight now we still recommend:
Don't use `{}` as a type. `{}` actually means "any non-nullish value".
- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.
- If you want a type meaning "any value", you probably want `unknown` instead.
- If you want a type meaning "empty object", you probably want `Record<string, never>` instead.
Additional Info
Originally suggested by @RyanCavanaugh in #5018.
Versions package version@typescript-eslint/eslint-plugin
5.42.1
@typescript-eslint/parser
5.42.1
TypeScript
4.8.4
ESLint
8.15.0
node
web
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4