1
有人可以幫我將下面的代碼從JavaScript轉換爲TypeScript嗎?Localstorage getitem和setitem JavaScript到TypeScript轉換
(function() {
'use strict';
angular.module('testUi').service('localStorage', localStorage);
localStorage.$inject = ['$window']
function localStorage ($window) {
var storage;
if ($window.localStorage) {
storage = $window.localStorage;
} else {
storage = {
items:[],
getItem: function(key) {
return this.items[key];
},
setItem: function(key,value) {
this.items[key] = value;
}
};
}
//exports
this.get = function (key) {
return storage.getItem(key);
};
this.set = function(key,value) {
storage.setItem(key,value);
};
}
}());
非常感謝Basart。 – user3125908
我收到了下面提到的錯誤app/js/components/localstorage/local-storage-service.ts(12,21):錯誤TS7006:參數'$ window'隱含有'any'類型。 app/js/components/localstorage/local-storage-service.ts(18,40):錯誤TS7006:參數'key'隱式具有'any'類型> app/js/components/localstorage/local-storage-service .ts(21,45):錯誤TS7006:參數'值'隱式具有'任何'類型。 – user3125908