diff --git a/src/core/singletons/object.ts b/src/core/singletons/object.ts index a26584d60..a3d2b9797 100644 --- a/src/core/singletons/object.ts +++ b/src/core/singletons/object.ts @@ -12,13 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -export type CoreObjectWithoutEmpty = { - [k in keyof T]: T[k] extends undefined | null ? never : T[k]; -}; +import { Pretty } from '@/core/utils/types'; -export type CoreObjectWithoutUndefined = { - [k in keyof T]: T[k] extends undefined ? never : T[k]; -}; +type ValueWithoutEmpty = T extends null | undefined ? never : T; +type ValueWithoutUndefined = T extends undefined ? never : T; + +export type CoreObjectWithoutEmpty = Pretty<{ + [k in keyof T]: ValueWithoutEmpty; +}>; + +export type CoreObjectWithoutUndefined = Pretty<{ + [k in keyof T]: ValueWithoutUndefined; +}>; /** * Singleton with helper functions for objects. diff --git a/src/core/utils/types.d.ts b/src/core/utils/types.d.ts new file mode 100644 index 000000000..f6b82e3e2 --- /dev/null +++ b/src/core/utils/types.d.ts @@ -0,0 +1,18 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * Helper type to flatten complex types. + */ +export type Pretty = T extends infer U ? {[K in keyof U]: U[K]} : never;