Skip to content

Instantly share code, notes, and snippets.

@codeAdrian
Created May 2, 2023 08:49
Show Gist options
  • Save codeAdrian/61823ec2b4bc66c9ee3b1146e9d0b50a to your computer and use it in GitHub Desktop.
Save codeAdrian/61823ec2b4bc66c9ee3b1146e9d0b50a 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;
balanceFormatted: string; // New property, no longer redefined
}
const adapter = (user: User) => {
// New properties
const newProps = {
fullName: "",
balanceFormatted: ""
};
return { ...user, ...newProps };
};
const handleGet = (obj: UserProxy, prop: string | symbol) => {
/* ... */
};
export const createUserDataProxy = (user: User): UserProxy => {
const proxy = new Proxy(adapter(user), {
get: handleGet,
});
return proxy;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment