I want to create an interface in typescript to receive this values:
{
"ABANDONED VEH": 4,
"ADMINISTRATION": 4,
"ALARM-BUS/RES": 4
}
When I try to use the correct interface that I create, I'm getting the error:
Type string is not assignable to
IMapping
What I'd already tried:
export interface IMapping {
[key: string]: { value: string };
}
export interface IMapping {
key: any;
}
[key: string]: string;
PS. Here's my real code:
file interface.ts:
export interface IMapping {
[key: string]: number;
}
file that use this interface:
import { IMapping } from '../interfaces';
const mapping: IMapping = '{'
+ '"ABANDONED VEH": 4,'
+ '"ADMINISTRATION": 4"}';
export interface IMapping { [key: string]: number; }[key: string]is not special is just any prop that is string (it's dynamic key from ES6 + type - where key is variable not value), you don't use the same for value.var a: IMapping[] = ["foo", {"ABANDONED VEH": 20,...}];or something like this.