Open DenizUgur opened 5 months ago
// @kkmuffme
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
The following code is considered as valid by Typescript, although I was expecting it to complain that the filter
foo
incommonArguments
was empty.Upvote & Fund