Skip to content

Instantly share code, notes, and snippets.

@MRezaSafari
Created September 4, 2022 07:39
Show Gist options
  • Save MRezaSafari/c5198e258885687522a8f2222f232dcd to your computer and use it in GitHub Desktop.
Save MRezaSafari/c5198e258885687522a8f2222f232dcd to your computer and use it in GitHub Desktop.
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;
@mu16zi
Copy link

mu16zi commented Aug 30, 2023

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 mind

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 🤷

@mu16zi
Copy link

mu16zi commented Aug 30, 2023

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 mind

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 🤷

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