Noel De Martin 2022-09-08 15:34:42 +02:00
parent 608ea978a0
commit 9f26620e03
2 changed files with 29 additions and 6 deletions

View File

@ -12,13 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
export type CoreObjectWithoutEmpty<T> = {
[k in keyof T]: T[k] extends undefined | null ? never : T[k];
};
import { Pretty } from '@/core/utils/types';
export type CoreObjectWithoutUndefined<T> = {
[k in keyof T]: T[k] extends undefined ? never : T[k];
};
type ValueWithoutEmpty<T> = T extends null | undefined ? never : T;
type ValueWithoutUndefined<T> = T extends undefined ? never : T;
export type CoreObjectWithoutEmpty<T> = Pretty<{
[k in keyof T]: ValueWithoutEmpty<T[k]>;
}>;
export type CoreObjectWithoutUndefined<T> = Pretty<{
[k in keyof T]: ValueWithoutUndefined<T[k]>;
}>;
/**
* Singleton with helper functions for objects.

18
src/core/utils/types.d.ts vendored 100644
View File

@ -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> = T extends infer U ? {[K in keyof U]: U[K]} : never;