Last active
September 8, 2023 03:11
-
-
Save edezekiel/82954d1e4f7f19dbdd3852b81fceaab3 to your computer and use it in GitHub Desktop.
Automatically add index signature to interface
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
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