-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add PublicInterface type #197
Conversation
I had need of this type in this PR: https://github.com/MetaMask/metamask-extension/pull/24503/files#diff-ea83e113f95081f8e48d8927c7b9ed1c532a69cfcaa812753ffe101e2fc85e09R18 I was considering referencing it in this ADR: https://github.com/MetaMask/decisions/pull/31 |
Add a type for deriving the "public interface" of a type, excluding private properties. Excluding private properties can be useful in making our classes more easily testable (types with private properties are more difficult to mock).
311cefa
to
af6e378
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool! I wasn't aware that this was possible. LGTM.
* | ||
* @template Interface - The interface to return a public representation of. | ||
*/ | ||
export type PublicInterface<Interface> = Pick<Interface, keyof Interface>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern with this is the name. It's a little weird to call this "PublicInterface" when it's a type, not an interface.
I meant "interface" in the English word sense, not like a TypeScript interface, but maybe there's a better name that can avoid this confusion.
I couldn't think of one though, and this seems good enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could call it PublicType
🤔 That doesn't have the same connotation as "public interface" though. Probably best as-is.
Add a type for deriving the "public interface" of a type, excluding private properties. Excluding private properties can be useful in making our classes more easily testable (types with private properties are more difficult to mock).