I have the following error in my typescript, and I have no idea how to get around it?
Parameter 'key' implicitly has an 'any' type.
Below is my code, I don't fully understand the problem, even if I type them any I get the error?
let store = {};
return {
getItem: (key) => {
return store[key] || null;
},
setItem: (key, value) => {
store[key] = value.toString();
},
removeItem: (key) => {
delete store[key];
},
clear: () => {
store = {};
},
};
};
The solution was typing the key at the point of the object creation
const fakeLocalStorage = () => {
let store: { [key: string]: string } = {};
return {
getItem: (key: string) => {
return store[key] || null;
},
setItem: (key: string, value: string) => {
store[key] = value.toString();
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
store = {};
},
};
};