Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try typing your store variable.

Something like this:

let store:{ [key: string]: string } = {};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading