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

NonEmptyObject fails for objects with dynamic properties #821

Open
DenizUgur opened this issue Feb 27, 2024 · 2 comments
Open

NonEmptyObject fails for objects with dynamic properties #821

DenizUgur opened this issue Feb 27, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@DenizUgur
Copy link

DenizUgur commented Feb 27, 2024

The following code is considered as valid by Typescript, although I was expecting it to complain that the filter foo in commonArguments was empty.

import type { NonEmptyObject } from "type-fest"

interface CommonArguments {
  [filter: string]: NonEmptyObject<{ [argument: string]: string | number | undefined }>
}

export const commonArguments: CommonArguments = {
  foo: {}
}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

// @kkmuffme

@kkmuffme
Copy link
Contributor

This issue isn't specific to NonEmptyObject but the same happens also with RequireAtLeastOne:

import type { RequireAtLeastOne } from "type-fest";

type Util = { [argument: string]: string | number | undefined };

interface CommonArguments {
  [filter: string]: RequireAtLeastOne<Util, keyof Util>
  
}

export const commonArguments: CommonArguments = {
  foo: {}
}

The fix for NonEmptyObject is relatively simple:

export type NonEmptyObject<T extends object> = HasRequiredKeys<T> extends true ? T : RequireAtLeastOne<T, keyof T>;

to

export type NonEmptyObject<T extends object> = HasRequiredKeys<OmitIndexSignature<T>> extends true ? T : RequireAtLeastOne<T, keyof T>;

However this issue will persist until someone fixes RequireAtLeastOne

@Emiyaaaaa Emiyaaaaa added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants