supabase/postgres-meta

Type error: Don't use `{}` as a type

probablykasper opened this issue · 4 comments

Bug report

Describe the bug

With v2 I get this error after having generated types, probably because of TS strict mode:

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.

due to the generated types including this:

export interface Database {
		Functions: {}
	}
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

TypeScript strict mode probably needs to be enabled.
Run supabase gen types typescript --local > databaseDefinitions.ts

System information

  • OS: macOS
  • Version of supabase-js: 2.0.0-rc.6
  • Version of Node.js: 16.15.0

The error seems to be coming from typescript-eslint. What do you suggest the replacement should be? Record<string, never> is not exactly correct, see microsoft/TypeScript#47486 (comment)

I don't really see why Record<string, never> doesn't fit. It doesn't seem like it's supposed to have any properties, so why would you ever need to access it's properties?

It needs to give a TS error when accessing a property, whereas Record<string, never> allows accessing properties (with value of type never).

Actually, Record<never, never> seems to work. It resolves to {} but seems to fool ts-eslint somehow.