Skip to content

Instantly share code, notes, and snippets.

@codeAdrian
Created May 2, 2023 08:40
Show Gist options
  • Save codeAdrian/96b324d4c0020cf6c876ed0a97f453bb to your computer and use it in GitHub Desktop.
Save codeAdrian/96b324d4c0020cf6c876ed0a97f453bb to your computer and use it in GitHub Desktop.
interface User {
firstName: string;
middleName?: string;
lastName: string;
email: string;
balance: number;
currency: string;
locale: string;
}
interface UserProxy extends User {
fullName: string; // new property
balance: string; // redefined propery
}
const handleGet = (obj: User, prop: string | symbol) => {
/* ... */
};
export const createUserDataProxy = (user: User): UserProxy => {
const proxy = new Proxy(user, {
get: handleGet,
}) as unknown as UserProxy;
return proxy;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment