Skip to content

Instantly share code, notes, and snippets.

@themgoncalves
Last active September 3, 2021 02:16
Show Gist options
  • Save themgoncalves/e191e9cccbcc0cf0c923f9b69ae82927 to your computer and use it in GitHub Desktop.
Save themgoncalves/e191e9cccbcc0cf0c923f9b69ae82927 to your computer and use it in GitHub Desktop.
Making JavaScript typeof() work - typescript demo
import typeOf from './type-of';
const shallowCompare: (source: Record<string, unknown | unknown[]>, target: Record<string, unknown | unknown[]>): boolean => {
if (typeOf(source) !== typeOf(target)) {
return false;
}
return Object.keys(source).every((key) => {
if (typeOf(source[key]) !== typeOf(target[key])) {
return false;
}
if (Array.isArray(source[key])) {
return (source[key] as unknown[]).length === (target[key] as unknown[]).length;
}
return source[key] === target[key];
});
},
};
@payom119
Copy link

payom119 commented Sep 3, 2021

dfdfd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment