Kabaner
Kabaner

Reputation: 25

Angular unit testing the localstorage, Error ts(7053)

beforeEach (() => { ...

   let store = {};
  const mockSessionStorage = {
  getItem: (key: string): string => key in store ? store[key] : null,
  setItem: (key: string, value: string) => store[key] = `${value}`,
  removeItem: (key: string) => delete store[key],
  clear: () => store = {}
};
...

and i get the Error Message The element implicitly has a type "any" because the expression of type "string" cannot be used for the index type "{}". No index signature with a parameter of type "string" was found for type "{}".ts(7053)

Also I'm new to typscript and don't know if it's because of the error message or if I'm doing something else wrong I would be happy if someone could take a quick look.

Upvotes: 0

Views: 338

Answers (1)

Try typing your store variable.

Something like this:

let store:{ [key: string]: string } = {};

Upvotes: 1

Related Questions