In the following demonstration, we have two objects - KEYS and KEYS2. When importing KEYS in index.ts
, autocomplete suggestions are available for K1
and K2
because KEYS
does not adhere to an interface.
On the other hand, with KEYS2, autocomplete is not provided as it implements an interface.
To access the StackBlitz demo, click here.
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 method to apply the interface while also enabling autocomplete for object keys simultaneously?
For instance, if we import KEYS2 and utilize it in a constructor:
constructor() {
const v = KEYS.
}
VSCode should provide us with the object properties as autocomplete suggestions?