Property 'location' does not exist on type 'typeof window'












0














My code was working until I upgraded the typescript and react frameworks.This error is happening on the line window.location.assign("#/home/dashboard");. I have read articles but still cannot resolve the issue. I also think the window property is from modernizer.js.
Currently, the error I have been getting when I try to run the project is below:




TS2339: Property 'location' does not exist on type 'typeof window'.




This is the code below



import RaisedButton from "material-ui/RaisedButton";
import {ActionLockOutline, SocialPerson} from "material-ui/svg-icons";
import * as React from "react";
import {hot} from "react-hot-loader";
import { OAuth } from "../../Shared/Services/OAuth";
import { Component, IComponentState } from "../../Shared/Utilities/Component";
import { Log } from "../../Shared/Utilities/LogUtil";
import { Validation } from "../../Shared/Utilities/Validation";

// import { StorageUtil } from "../../Shared/Utilities/StorageUtil";

interface ILoginState extends IComponentState {
userName: string;
password: string;
}

class Form extends Component<any, ILoginState> {

constructor(props: any) {
super(props,
{
password: "",
userName: "",
});

}

public loginClick = () => {
// this.warningNoti("All fields marked red are required");

if (Validation.formValidation("#loginForm")) {
OAuth.userLogin(this.state.userName, this.state.password, (loginResponse: any) => {
Log.consoleObj(loginResponse);

this.successNoti("User successfully logged in");

window.location.assign("#/home/dashboard");

}, (status: string, jqXhr: any) => {
// console.log(status);
// console.log(jqXhr);
this.setState({password: ""});
this.infoNoti("Incorrect username or password, please check credentials.");
});
} else {
this.warningNoti("All fields marked red are required");
}

}
}









share|improve this question






















  • Are you using react-router? In that case the idiomatic way to navigate would be this.props.history.push('/new/route/here')
    – Jonas Høgh
    Nov 12 at 11:57










  • Yes I'm using react-router. You want me to use the code you sent to redirect the page?
    – King J
    Nov 12 at 12:03










  • Yes, you can use the code above in place of window.location.assign
    – Jonas Høgh
    Nov 12 at 13:29
















0














My code was working until I upgraded the typescript and react frameworks.This error is happening on the line window.location.assign("#/home/dashboard");. I have read articles but still cannot resolve the issue. I also think the window property is from modernizer.js.
Currently, the error I have been getting when I try to run the project is below:




TS2339: Property 'location' does not exist on type 'typeof window'.




This is the code below



import RaisedButton from "material-ui/RaisedButton";
import {ActionLockOutline, SocialPerson} from "material-ui/svg-icons";
import * as React from "react";
import {hot} from "react-hot-loader";
import { OAuth } from "../../Shared/Services/OAuth";
import { Component, IComponentState } from "../../Shared/Utilities/Component";
import { Log } from "../../Shared/Utilities/LogUtil";
import { Validation } from "../../Shared/Utilities/Validation";

// import { StorageUtil } from "../../Shared/Utilities/StorageUtil";

interface ILoginState extends IComponentState {
userName: string;
password: string;
}

class Form extends Component<any, ILoginState> {

constructor(props: any) {
super(props,
{
password: "",
userName: "",
});

}

public loginClick = () => {
// this.warningNoti("All fields marked red are required");

if (Validation.formValidation("#loginForm")) {
OAuth.userLogin(this.state.userName, this.state.password, (loginResponse: any) => {
Log.consoleObj(loginResponse);

this.successNoti("User successfully logged in");

window.location.assign("#/home/dashboard");

}, (status: string, jqXhr: any) => {
// console.log(status);
// console.log(jqXhr);
this.setState({password: ""});
this.infoNoti("Incorrect username or password, please check credentials.");
});
} else {
this.warningNoti("All fields marked red are required");
}

}
}









share|improve this question






















  • Are you using react-router? In that case the idiomatic way to navigate would be this.props.history.push('/new/route/here')
    – Jonas Høgh
    Nov 12 at 11:57










  • Yes I'm using react-router. You want me to use the code you sent to redirect the page?
    – King J
    Nov 12 at 12:03










  • Yes, you can use the code above in place of window.location.assign
    – Jonas Høgh
    Nov 12 at 13:29














0












0








0







My code was working until I upgraded the typescript and react frameworks.This error is happening on the line window.location.assign("#/home/dashboard");. I have read articles but still cannot resolve the issue. I also think the window property is from modernizer.js.
Currently, the error I have been getting when I try to run the project is below:




TS2339: Property 'location' does not exist on type 'typeof window'.




This is the code below



import RaisedButton from "material-ui/RaisedButton";
import {ActionLockOutline, SocialPerson} from "material-ui/svg-icons";
import * as React from "react";
import {hot} from "react-hot-loader";
import { OAuth } from "../../Shared/Services/OAuth";
import { Component, IComponentState } from "../../Shared/Utilities/Component";
import { Log } from "../../Shared/Utilities/LogUtil";
import { Validation } from "../../Shared/Utilities/Validation";

// import { StorageUtil } from "../../Shared/Utilities/StorageUtil";

interface ILoginState extends IComponentState {
userName: string;
password: string;
}

class Form extends Component<any, ILoginState> {

constructor(props: any) {
super(props,
{
password: "",
userName: "",
});

}

public loginClick = () => {
// this.warningNoti("All fields marked red are required");

if (Validation.formValidation("#loginForm")) {
OAuth.userLogin(this.state.userName, this.state.password, (loginResponse: any) => {
Log.consoleObj(loginResponse);

this.successNoti("User successfully logged in");

window.location.assign("#/home/dashboard");

}, (status: string, jqXhr: any) => {
// console.log(status);
// console.log(jqXhr);
this.setState({password: ""});
this.infoNoti("Incorrect username or password, please check credentials.");
});
} else {
this.warningNoti("All fields marked red are required");
}

}
}









share|improve this question













My code was working until I upgraded the typescript and react frameworks.This error is happening on the line window.location.assign("#/home/dashboard");. I have read articles but still cannot resolve the issue. I also think the window property is from modernizer.js.
Currently, the error I have been getting when I try to run the project is below:




TS2339: Property 'location' does not exist on type 'typeof window'.




This is the code below



import RaisedButton from "material-ui/RaisedButton";
import {ActionLockOutline, SocialPerson} from "material-ui/svg-icons";
import * as React from "react";
import {hot} from "react-hot-loader";
import { OAuth } from "../../Shared/Services/OAuth";
import { Component, IComponentState } from "../../Shared/Utilities/Component";
import { Log } from "../../Shared/Utilities/LogUtil";
import { Validation } from "../../Shared/Utilities/Validation";

// import { StorageUtil } from "../../Shared/Utilities/StorageUtil";

interface ILoginState extends IComponentState {
userName: string;
password: string;
}

class Form extends Component<any, ILoginState> {

constructor(props: any) {
super(props,
{
password: "",
userName: "",
});

}

public loginClick = () => {
// this.warningNoti("All fields marked red are required");

if (Validation.formValidation("#loginForm")) {
OAuth.userLogin(this.state.userName, this.state.password, (loginResponse: any) => {
Log.consoleObj(loginResponse);

this.successNoti("User successfully logged in");

window.location.assign("#/home/dashboard");

}, (status: string, jqXhr: any) => {
// console.log(status);
// console.log(jqXhr);
this.setState({password: ""});
this.infoNoti("Incorrect username or password, please check credentials.");
});
} else {
this.warningNoti("All fields marked red are required");
}

}
}






javascript reactjs typescript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 11:50









King J

31




31












  • Are you using react-router? In that case the idiomatic way to navigate would be this.props.history.push('/new/route/here')
    – Jonas Høgh
    Nov 12 at 11:57










  • Yes I'm using react-router. You want me to use the code you sent to redirect the page?
    – King J
    Nov 12 at 12:03










  • Yes, you can use the code above in place of window.location.assign
    – Jonas Høgh
    Nov 12 at 13:29


















  • Are you using react-router? In that case the idiomatic way to navigate would be this.props.history.push('/new/route/here')
    – Jonas Høgh
    Nov 12 at 11:57










  • Yes I'm using react-router. You want me to use the code you sent to redirect the page?
    – King J
    Nov 12 at 12:03










  • Yes, you can use the code above in place of window.location.assign
    – Jonas Høgh
    Nov 12 at 13:29
















Are you using react-router? In that case the idiomatic way to navigate would be this.props.history.push('/new/route/here')
– Jonas Høgh
Nov 12 at 11:57




Are you using react-router? In that case the idiomatic way to navigate would be this.props.history.push('/new/route/here')
– Jonas Høgh
Nov 12 at 11:57












Yes I'm using react-router. You want me to use the code you sent to redirect the page?
– King J
Nov 12 at 12:03




Yes I'm using react-router. You want me to use the code you sent to redirect the page?
– King J
Nov 12 at 12:03












Yes, you can use the code above in place of window.location.assign
– Jonas Høgh
Nov 12 at 13:29




Yes, you can use the code above in place of window.location.assign
– Jonas Høgh
Nov 12 at 13:29












1 Answer
1






active

oldest

votes


















0














First Answering your question: Why tslint raises that "Property 'location' does not exist on type 'window'. It is because Typescript has some set of types defined, default types and custom types. For typescript window is custom type. Default types are number, string,boolean,any,etc. So when you want to use window, it is treated as a window object which has functions like assign, location and so on defined as interface in default lib.dom.d.ts. For now I suggest a work around for you by creating a const with type set as any.
reference: https://www.typescriptlang.org/docs/handbook/basic-types.html


Solution/Workaround: set type of your constant by yourself by doing this :



const temp: any = window;
temp.location.assign('#/home/dashboard');





share|improve this answer





















  • Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
    – King J
    Nov 12 at 13:31










  • sorry but further I can't assist as I have limited knowledge of webpack :(
    – Ramakant Singh
    Nov 13 at 4:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261558%2fproperty-location-does-not-exist-on-type-typeof-window%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














First Answering your question: Why tslint raises that "Property 'location' does not exist on type 'window'. It is because Typescript has some set of types defined, default types and custom types. For typescript window is custom type. Default types are number, string,boolean,any,etc. So when you want to use window, it is treated as a window object which has functions like assign, location and so on defined as interface in default lib.dom.d.ts. For now I suggest a work around for you by creating a const with type set as any.
reference: https://www.typescriptlang.org/docs/handbook/basic-types.html


Solution/Workaround: set type of your constant by yourself by doing this :



const temp: any = window;
temp.location.assign('#/home/dashboard');





share|improve this answer





















  • Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
    – King J
    Nov 12 at 13:31










  • sorry but further I can't assist as I have limited knowledge of webpack :(
    – Ramakant Singh
    Nov 13 at 4:26
















0














First Answering your question: Why tslint raises that "Property 'location' does not exist on type 'window'. It is because Typescript has some set of types defined, default types and custom types. For typescript window is custom type. Default types are number, string,boolean,any,etc. So when you want to use window, it is treated as a window object which has functions like assign, location and so on defined as interface in default lib.dom.d.ts. For now I suggest a work around for you by creating a const with type set as any.
reference: https://www.typescriptlang.org/docs/handbook/basic-types.html


Solution/Workaround: set type of your constant by yourself by doing this :



const temp: any = window;
temp.location.assign('#/home/dashboard');





share|improve this answer





















  • Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
    – King J
    Nov 12 at 13:31










  • sorry but further I can't assist as I have limited knowledge of webpack :(
    – Ramakant Singh
    Nov 13 at 4:26














0












0








0






First Answering your question: Why tslint raises that "Property 'location' does not exist on type 'window'. It is because Typescript has some set of types defined, default types and custom types. For typescript window is custom type. Default types are number, string,boolean,any,etc. So when you want to use window, it is treated as a window object which has functions like assign, location and so on defined as interface in default lib.dom.d.ts. For now I suggest a work around for you by creating a const with type set as any.
reference: https://www.typescriptlang.org/docs/handbook/basic-types.html


Solution/Workaround: set type of your constant by yourself by doing this :



const temp: any = window;
temp.location.assign('#/home/dashboard');





share|improve this answer












First Answering your question: Why tslint raises that "Property 'location' does not exist on type 'window'. It is because Typescript has some set of types defined, default types and custom types. For typescript window is custom type. Default types are number, string,boolean,any,etc. So when you want to use window, it is treated as a window object which has functions like assign, location and so on defined as interface in default lib.dom.d.ts. For now I suggest a work around for you by creating a const with type set as any.
reference: https://www.typescriptlang.org/docs/handbook/basic-types.html


Solution/Workaround: set type of your constant by yourself by doing this :



const temp: any = window;
temp.location.assign('#/home/dashboard');






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 12:17









Ramakant Singh

1016




1016












  • Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
    – King J
    Nov 12 at 13:31










  • sorry but further I can't assist as I have limited knowledge of webpack :(
    – Ramakant Singh
    Nov 13 at 4:26


















  • Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
    – King J
    Nov 12 at 13:31










  • sorry but further I can't assist as I have limited knowledge of webpack :(
    – Ramakant Singh
    Nov 13 at 4:26
















Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
– King J
Nov 12 at 13:31




Your suggestion removed the errors but now webpack.config.js also generates errors for the path,"Cannot compile namespaces when the '--isolatedModules' flag is provided.".Now this one too is confusing
– King J
Nov 12 at 13:31












sorry but further I can't assist as I have limited knowledge of webpack :(
– Ramakant Singh
Nov 13 at 4:26




sorry but further I can't assist as I have limited knowledge of webpack :(
– Ramakant Singh
Nov 13 at 4:26


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261558%2fproperty-location-does-not-exist-on-type-typeof-window%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python