Created
September 4, 2022 07:39
-
-
Save MRezaSafari/c5198e258885687522a8f2222f232dcd to your computer and use it in GitHub Desktop.
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
function serverObjectsSanitizer<T>(input: T, ignoreList: string[]): T { | |
if (Array.isArray(input)) | |
return input.map((i) => | |
serverObjectsSanitizer(i, ignoreList) | |
) as unknown as T; | |
if (typeof input == 'object' && input != null) | |
return Object.keys(input).reduce((t, c) => { | |
const before = input[c]; | |
if (ignoreList.indexOf(c) > -1) { | |
delete t[c]; | |
} else { | |
t[c] = serverObjectsSanitizer(before, ignoreList); | |
} | |
return t; | |
}, {}) as unknown as T; | |
return input as unknown as T; | |
} | |
export default serverObjectsSanitizer; |
it's a simple function that accepts a generic type and returns it as it should ...
I think its because you don't understand it. that's why you hate it.hate TypeScript, makes the code look dump
maybe report abuse cause its really abusing my mindThere is a piece of statically typed wrapper to a dynamic type system that is a syntax sugar to a strongly typed language itself btw 🤷
That's why I hate it. Otherwise, there is NOTHING difficult in this code that makes it hard to understand :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a piece of statically typed wrapper to a dynamic type system that is a syntax sugar to a strongly typed language itself btw 🤷