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

setTimeout intercepted and requires Timer type variable to be assigned to #901

Closed
jeserkin opened this issue May 19, 2016 · 5 comments
Closed

Comments

@jeserkin
Copy link

jeserkin commented May 19, 2016

IMPORTANT: This repository's issues are reserved for feature requests and bug reports. Do not submit support requests here.

Steps to reproduce and a minimal demo of the problem

What steps should we try in your demo to see the problem?

  1. Create class
import { Component, OnDestroy } from "@angular/core";

@Component({
  selector: 'sample',
  tempalte: '<div></div>'
})
class SampleComponent implements OnDestroy {
  private currentTimeout: number;

  public sampleMethodCall() {
    this.currentTimeout = setTimeout(() => {
      alert('working');
    }, 300);
  }

  ngOnDestroy(): any {
    return undefined;
  }
}
  1. Save
  2. Watch comiler consile livereload

Current behavior
On *.ts file change comiler in console shows following error
.component.ts(27,5): error TS2322: Type 'Timer' is not assignable to type 'number'.

Expected/desired behavior
Like in every setTimeout TypeScript tutorial on the web. Excpect it to return number type result, not Timer.

@mgechev
Copy link
Owner

mgechev commented May 19, 2016

Here's the first result when Googling the error you have, i.e.:

...
this.currentTimeout = window.setTimeout(() => {
  alert('working');
}, 300);
...

solves your problem.

@mgechev mgechev closed this as completed May 19, 2016
@jeserkin
Copy link
Author

jeserkin commented May 19, 2016

Okay, but all examples on the internet don't need it to be specified. Is it only angular2-seed issue due to some typings override(priority)?

@ludohenin
Copy link
Collaborator

ludohenin commented May 19, 2016

I think it is due to a core node.d.ts lib in typescript.

@nadavsinai
Copy link

@mgechev isn't adding window.XXXXXX breaks the possibility of running the app in server/worker based rendering scenario? I thought removing the node.js type definitions would help but unfortunately it doesn't seem to work, any other ideas?

@mgechev
Copy link
Owner

mgechev commented Apr 20, 2017

@nadavsinai yes, you're correct. Directly accessing window will prevent your application from running in Web Worker/Server.

jvanveen pushed a commit to molgenis/molgenis-ui-context that referenced this issue Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants