Last active
January 24, 2025 21:28
-
-
Save ryangoree/cf69f0d37a290d14bae4100f7c6c1ddb to your computer and use it in GitHub Desktop.
Get a superset of `T` that allows for arbitrary properties.
This file contains hidden or 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
/** | |
* Get a superset of `T` that allows for arbitrary properties. | |
* | |
* @example | |
* | |
* ```ts | |
* interface Order { | |
* account: `0x${string}`; | |
* amount: bigint; | |
* } | |
* | |
* const order1: Order = { | |
* account: "0x123", | |
* amount: 100n, | |
* getStatus() { ... } | |
* // ^ Object literal may only specify known properties, and 'getStatus' does not exist in type 'Order'. | |
* }; | |
* | |
* // No errors! 🎉 | |
* const order2: Extended<Order> = { | |
* account: "0x123", | |
* amount: 100n, | |
* getStatus() { ... } | |
* }; | |
* ``` | |
* | |
*/ | |
export type Extended<T extends object> = T & | |
Record<Exclude<PropertyKey, keyof T>, unknown>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment