Skip to content

Instantly share code, notes, and snippets.

@edezekiel
Last active September 8, 2023 03:11
Show Gist options
  • Save edezekiel/82954d1e4f7f19dbdd3852b81fceaab3 to your computer and use it in GitHub Desktop.
Save edezekiel/82954d1e4f7f19dbdd3852b81fceaab3 to your computer and use it in GitHub Desktop.
Automatically add index signature to interface
type IndexSignature<T extends {}> = {
[K in keyof T]: T[K];
};
interface Hero { name: string; }
const hero: Hero = { name: 'codey' };
function addIndexSignature<T extends {}>(obj: T): IndexSignature<T> {
return obj;
}
parseObject(addIndexSignature(hero));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment