Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  36] [ 1]  / answers: 1 / hits: 109664  / 12 Years ago, sun, october 28, 2012, 12:00:00

I am getting an error with the following TypeScript code:



 ///<reference path='../../../Shared/typescript/jquery.d.ts' />
///<reference path='../../../Shared/typescript/jqueryStatic.d.ts' />

function accessControls(action: Action) {
$('#logoutLink')
.click(function () {
var $link = $(this);
window.location = $link.attr('data-href');
});

}


I am getting an underlined red error for the following:



$link.attr('data-href'); 


The message says:



Cannot convert 'string' to 'Location': Type 'String' is missing property 'reload' from type 'Location'


Does anyone know what this means?


More From » jquery

 Answers
40

window.location is of type Location while .attr('data-href') returns a string, so you have to assign it to window.location.href which is of string type too. For that replace your following line:



window.location = $link.attr('data-href');


for this one:



window.location.href = $link.attr('data-href');

[#82313] Friday, October 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adam

Total Points: 363
Total Questions: 102
Total Answers: 104

Location: Burkina Faso
Member since Thu, Dec 15, 2022
2 Years ago
;