This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see https://repl.it/repls/AnimatedPerfectMinimalsystem | |
// 1 Transform the type to flag all the undesired keys as 'never' | |
type FlagExcludedType<Base, Type> = { [Key in keyof Base]: Base[Key] extends Type ? never : Key }; | |
// 2 Get the keys that are not flagged as 'never' | |
type AllowedNames<Base, Type> = FlagExcludedType<Base, Type>[keyof Base]; | |
// 3 Use this with a simple Pick to get the right interface, excluding the undesired type | |
type OmitType<Base, Type> = Pick<Base, AllowedNames<Base, Type>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see https://repl.it/repls/TemporalFrigidScientificcomputing | |
type DataPropertyNames<T> = { | |
[K in keyof T]: T[K] extends Function ? never : K; | |
}[keyof T]; | |
type DataPropertiesOnly<T> = { | |
[P in DataPropertyNames<T>]?: T[P] extends object ? DTO<T[P]> : T[P] | |
}; | |
export type DTO<T> = DataPropertiesOnly<T>; |