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

Comments

Projects
None yet
9 participants
@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

This comment has been minimized.

Copy link

FleaMann commented Oct 26, 2016

I'm also having this issue.

@guncha

This comment has been minimized.

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

This comment has been minimized.

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

dmitrykurmanov added a commit to surveyjs/survey-creator that referenced this issue Nov 24, 2017

@ollwenjones

This comment has been minimized.

Copy link

ollwenjones commented Dec 1, 2017

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

@fwchen

This comment has been minimized.

Copy link

fwchen commented Jan 17, 2018

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

@ThAlmighty

This comment has been minimized.

Copy link

ThAlmighty commented Jan 26, 2018

same here, really annoying

@lierdakil

This comment has been minimized.

Copy link
Collaborator

lierdakil commented Jan 26, 2018

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

@lierdakil lierdakil closed this Jan 26, 2018

@fider

This comment has been minimized.

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

This comment has been minimized.

Copy link
Collaborator

lierdakil commented Feb 1, 2018

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.
You can’t perform that action at this time.