I'am learning typescript and i don't know how to solve this.
My goal is to find a key: string in some random text and replace it with the value: string.
export class Smiley {
private smiley: {[key: string]: {value: string}} = {
':-)': '°>sm_00...b.pw_18.ph_18.gif<°',
':-(': '°>sm_03...b.pw_18.ph_18.gif<°',
':-|': '°>sm_13...b.pw_18.ph_18.gif<°',
':-D': '°>sm_10...b.pw_18.ph_18.gif<°',
':-O': '°>sm_06...b.pw_18.ph_18.gif<°',
};
tbsmiley(str: string): string {
const obj = this.smiley;
Object.keys(obj).forEach((key) => {
const ind = str.indexOf(key);
if ( ind >= 0 ) {
str = str.substring(0, ind) + obj[key] + str.substr(ind + key.length);
return str;
}
});
return str;
}
}
Type 'string' is not assignable to type '{ value: string; }'. The expected type comes from this index signature.