How to initialize {[key: string]: string} to {} in TypeScript?

Viewed 334
interface a {
    d: {[key: string]: string}
}

class a {
    d = {}
}

returns the following error :

Subsequent property declarations must have the same type. Property 'd' must be of type '{ [key: string]: string; }', but here has type '{}'.

let v: {[key: string]: string} = {}

is accepted without warning/error

What I am missing ?

1 Answers

Your interface and class have the same name - a. Rename one of them to something else. What you are looking for is probably something like this:

class b implements a {
    d = {}
}
Related