In this demo there are two objects. KEYS and KEYS2. If we import KEYS in index.ts we get autocomplete for K1 and K2 because KEYS does not implement an interface.
With KEYS2 we don't because it implements an interface.
export interface IKeyObject {
[key:string]: IKeyValue | any
}
export interface IKeyValue {
key:string
value:any
}
export const KEYS = {
K1: 'K1',
K2: 'K2'
}
export const KEYS2:IKeyObject = {
K1: { key:'', value:''},
K2: {key:'', value:''}
}
Is there a way to implement the interface and get autocomplete for the keys on the object at the same time?
So in other words if we import KEYS2, and us it in a constructor:
constructor() {
const v = KEYS.
}
VSCode will give us the properties on the object as autocomplete values?