Last active
July 8, 2019 11:32
-
-
Save sean-nicholas/f62ea2d353c57c3dd1f7fd4ef3e6c7d8 to your computer and use it in GitHub Desktop.
dynamic key
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
| interface IdMappingDoc { | |
| firstId: string, | |
| secondId: string, | |
| } | |
| interface IdMappingConfig { | |
| sourceIdField: 'firstId' | 'secondId' | |
| targetIdField: 'firstId' | 'secondId' | |
| } | |
| const idMappingConfig: IdMappingConfig = { | |
| sourceIdField: 'firstId', | |
| targetIdField: 'secondId' | |
| } | |
| function doStuff(idMapping: IdMappingDoc) { | |
| } | |
| // ERROR: | |
| // Argument of type '{ [x: string]: string; }' | |
| // is not assignable to parameter of type 'IdMappingDoc'. | |
| // Type '{ [x: string]: string; }' is missing the following | |
| // properties from type 'IdMappingDoc': firstId, secondId | |
| doStuff({ | |
| [idMappingConfig.sourceIdField]: 'foo', | |
| [idMappingConfig.targetIdField]: 'bar' | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment