Skip to content

Instantly share code, notes, and snippets.

@codeAdrian
Created May 2, 2023 08:46
Show Gist options
  • Save codeAdrian/ff888cd5491da4a40a5b0a5413b6da30 to your computer and use it in GitHub Desktop.
Save codeAdrian/ff888cd5491da4a40a5b0a5413b6da30 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;
balance: string;
}
const adapter = (user: User) => {
// Redefined properties
const balance = user.balance as unknown as string;
// New properties
const newProps = {
fullName: "",
};
return { ...user, ...newProps, balance };
};
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