Skip to content

Enhancement: [no-empty-object-type] Checks for generated empty-object-type #10619

Open
@yeonjuan

Description

@yeonjuan

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-empty-object-type/

Description

I suggest that the no-empty-object-type rule also disallows {} generated by type transformations.
For example, using Omit<V,K> on a type that is nullable will unintentionally create a {} type.

type NullableData = null | { name: string;  num: number };
type ITS_EMPTY_OBJECT_TYPE = Omit<NullableData, 'name'>; // '{}'

Fail

type Data = { name: string; num: number };
type NullableData = null | Data;

function doSomething<T extends Omit<NullableData, 'name'> // lint error
>(param: T) { }

type Unexpected = Omit<NullableData, 'name'>; // lint error

Pass

type Data = { name: string; num: number };

function doSomething<T extends Omit<Data, 'name'>>(param: T) { }

type Expected = Omit<Data, 'name'>;

Additional Info

Perhaps it would be appropriate to handle this in no-unsafe-*?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleevaluating community engagementwe're looking for community engagement on this issue to show that this problem is widely importantpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions