Skip to content

Property Math is missing on Window interface #9325

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

Closed
zuzusik opened this issue Jun 23, 2016 · 1 comment
Closed

Property Math is missing on Window interface #9325

zuzusik opened this issue Jun 23, 2016 · 1 comment
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@zuzusik
Copy link

zuzusik commented Jun 23, 2016

TypeScript Version:

1.8.10

Code

window.Math.round(1.35);

Expected behavior:
compiled

Actual behavior:
error TS2339: Property 'Math' does not exist on type 'Window'

PS: Math.round(1.35) works as expected, but I want to access it from window in order to be able to mock this method in Angular unit tests by mocking $window service.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 23, 2016

The standard library does not support using Window as the global polluter. i.e. adding members on Window are not reflected on the global and adding members on the global are not reflected on Window. The rational is to limit the ways a construct is accessible, and generally accessing global through window is not recommended.

if you want to expose Math, or any other declaration on window, you can augment the Window interface:

interface Window {
    Math: typeof Math;
}

@mhegazy mhegazy added Working as Intended The behavior described is the intended behavior; this is not a bug Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jun 23, 2016
@mhegazy mhegazy closed this as completed Jun 23, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants