Created
May 2, 2023 08:40
-
-
Save codeAdrian/96b324d4c0020cf6c876ed0a97f453bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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