Skip to content

"Self" variable assumes window environment at the top level #3238

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
ChimeraCoder opened this issue May 20, 2015 · 6 comments
Closed

"Self" variable assumes window environment at the top level #3238

ChimeraCoder opened this issue May 20, 2015 · 6 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@ChimeraCoder
Copy link

I'm using Typescript to write a content script for a Firefox extension. These run in a special environment in which a number of variables are pre-defined, self being one of them. I can use declare var content;, etc. to access them in TypeScript easily.

However, they do not run in the window environment (at least not directly), so window may not be defined, and self does not refer to window.self. Yet, when I do declare var self;, I get the following error:

error TS2403: Subsequent variable declarations must have the same type.  Variable 'self' must be of type 'Window', but here has type 'any'

So far, I haven't been able to find a way to convince tsc that self is actually a different type. This surprised me, because as far as I know, Typescript is not specific to the browser context. Should there be a flag to specify the runtime environment (or absence of one)?

@DanielRosenwasser
Copy link
Member

You could in theory customize our lib.d.ts, remove the declaration, include the new file into your source, and compile with --noLib. Not sure if we really have a better solution at this point.

@saschanaz
Copy link
Contributor

I wanted redeclare foo: Bar thing every time I encountered this kind of problem.

@mhegazy
Copy link
Contributor

mhegazy commented May 21, 2015

looks like what you want is to explicitly reference lib.code.d.ts, this does not have any DOM definitions, so no self, no window, this would be what you need for node development. the file is available in the same location as your tsc.ex/tsc.js, just add a reference to it on your commandline or in your project, and you should be good to go.

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label May 21, 2015
@mhegazy
Copy link
Contributor

mhegazy commented May 21, 2015

also to add more context, we did split the lib into multiple smaller files(e.g. core, dom, webworkers, wscript, ...etc.), but we are still looking into easier ways to surface this change. it is on the list of work items for 2.0 (see roadmap).

@ChimeraCoder
Copy link
Author

Got it - thanks for clarifying. As per your comment in #2953, I think eventually a --lib flag would indeed solve this problem in the long run.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 12, 2015

Looks like there is no further information needed at this point. closing.

@mhegazy mhegazy closed this as completed Jun 12, 2015
@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants