typescript make a key equal to spcific strings code example
Example 1: typescriprt specify type of key
var stuff: { [key: string]: string; } = {};
stuff['a'] = '';
stuff['a'] = 4;
interface StringMap { [key: string]: string; }
var stuff2: StringMap = { };
Example 2: typescript string in object property
protected get ButtonClass(): object {
const buttonClass = {
'cursor-pointer hover:shadow focus:shadow': this.Enabled,
'opacity-40 cursor-not-allowed': !this.Enabled,
'whitespace-no-wrap': !this.LineBreaks
}
buttonClass[`hover:${this.Color.FocusColorClass}`] = this.Enabled;
buttonClass[`focus:${this.Color.FocusColorClass}`] = this.Enabled;
buttonClass[`active:${this.Color.ActiveColorClass}`] = this.Enabled;
return buttonClass;
}