Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setInterval - Type 'Timer' is not assignable to type 'number' #1053

Closed
AskYous opened this issue Aug 16, 2016 · 9 comments
Closed

setInterval - Type 'Timer' is not assignable to type 'number' #1053

AskYous opened this issue Aug 16, 2016 · 9 comments

Comments

@AskYous
Copy link

AskYous commented Aug 16, 2016

I am attempting to create an interval for a web app. But in the browser, setInterval() returns a number representing the ID of that interval. But instead, atom-typescript is saying it returns a NodeJS.Timer object. It seems it's the wrong overload method.

In short, the following works in the TypeScript playground, but doesn't work in atom-typescript:

let interval: number = setInterval(() => { }, 1000);
// Throws: "Type 'Timer' is not assignable to type 'number'" in atom-typescript.
@FleaMann
Copy link

I'm also having this issue.

@guncha
Copy link
Contributor

guncha commented Oct 26, 2016

It seems like you are using node typings which override setInterval() as something that returns NodeJS.Timer. If you're running in the browser, it doesn't make a whole lot of sense to use these, except for the definition of require and you can get that by adding the following line to your project:

declare function require(name: string): any

@SRHerzog
Copy link

SRHerzog commented Aug 9, 2017

Use window.setInterval instead.

returnlytom added a commit to returnlytom/ng2-tooltip-directive that referenced this issue Aug 10, 2017
dmitry-kurmanov added a commit to surveyjs/survey-creator that referenced this issue Nov 24, 2017
@ollwenjones
Copy link

Seems like a lame work-around, but I guess since difficult to determine which dependency in a large project introduced the ambient node types...

@can-cc
Copy link

can-cc commented Jan 17, 2018

I'm also having this issue in NodeJs.
window.setInterval and global. setInterval not work

@ThAlmighty
Copy link

same here, really annoying

@lierdakil
Copy link
Collaborator

Okay, complain about this on the TypeScript repo. We have zero control over how ambient types are resolved.

@fider
Copy link

fider commented Feb 1, 2018

Before resolved just use this for your browser code:
let interval: number = <any>setInterval( ()=>{} )

@TypeStrong TypeStrong locked as resolved and limited conversation to collaborators Feb 1, 2018
@lierdakil
Copy link
Collaborator

As @SRHerzog suggested, use window.setInterval, or figure out what brings in ambient NodeJS types and nuke it (likely @types/node). I'm locking the conversation because this is getting out of hand.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants