Say one has following JSON file…
{
"hardened-computer": {
"metadata": {
"title": "How to verify integrity of release?"
},
"content": "foo"
},
"release-integrity": {
"metadata": {
"title": "What is a hardened computer?"
},
"content": "bar"
}
}
…and one imports file in TypeScript project which uses part of URI as property key (example: /faq/[topic]
).
How can one infer object property type SomeType
?
import faq from "./faq.json"
const topic = getTopic() // returns hardened-computer, release-integrity or any other topic from URI
let topicData: SomeType
…
topicData = faq[topic as keyof typeof faq]