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

ban-types gives misleading/wrong suggestion for empty object on generic bounds #1260

Open
lucasavila00 opened this issue Mar 9, 2024 · 0 comments

Comments

@lucasavila00
Copy link

I had code that relied on the empty object having no keys. Accepting the linter suggestion broke this.

type X = {}
// `{}` doesn't mean an empty object, but means any types other than `null` and `undefined`
// If you want a type that means "empty object", use `Record<string | number | symbol, never>` instead
// deno-lint(ban-types)
type Y = keyof X // never

type X2 = Record<string | number | symbol, never>
type Y2 = keyof X2 // string | number | symbol

type X3 = Record<never,never>
type Y3 = keyof X3 // never

I ended up using Record<never, never>.

In my case, I was using this as a generic bound

const x = <T extends Record<string,string> = {}>(a: T):T => a

Should the message change if the empty record is a generic bound?

@lucasavila00 lucasavila00 changed the title ban-types gives misleading/wrong suggestion ban-types gives misleading/wrong suggestion for empty object on generic bounds Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant