I used a module can do such thing
function print(obj, key) {
console.log(obj[key])
}
print({'test': 'content'}, '/* vs code will show code recommendation when typing */')
I want to have this feature but I forgot the name of the module and I even don't sure if I misremembered (maybe it's impossible).
I'm working on a package and have a code like this:
interface Box {
content: {
[key: string]: string
}
using: string // key of content
}
const box: Box = {
content: {
'something': 'inside'
},
using: 'something'
}
function showBox(box: Box) {
console.log(box.content[box.using])
}
Actually the content is a object comes from another package using typescript. I would like not to wrap the type if possible.
To help devs can find bugs during coding, I'm looking for if there is a way to check invalid Box type like:
const box: Box = {
content: {
'something': 'inside'
},
using: 'samething' // raise error when checking type
}
Or any way can make code recommendation of IDE know the using should be a key of content object.
My code currently looks like this but it's not what I want, and I don't have any idea to go on
interface Box {
content: {
[key: string]: string
}
using: keyof Box['content'] // will be string | number
}
Thanks to all response