Skip to content

Instantly share code, notes, and snippets.

@ryangoree
Last active January 24, 2025 21:28
Show Gist options
  • Save ryangoree/cf69f0d37a290d14bae4100f7c6c1ddb to your computer and use it in GitHub Desktop.
Save ryangoree/cf69f0d37a290d14bae4100f7c6c1ddb to your computer and use it in GitHub Desktop.
Get a superset of `T` that allows for arbitrary properties.
/**
* 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