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

Setting to set execution environnement (node or browser) #11050

Closed
testerez opened this issue Sep 21, 2016 · 11 comments
Closed

Setting to set execution environnement (node or browser) #11050

testerez opened this issue Sep 21, 2016 · 11 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@testerez
Copy link

When coding for node, It feels strange to have all the stuff specific to browser available by default.
For example, this is compiled with no warning by tsc 2.0.2:

alert(name); // name and alert are part of lib.d.ts

Maybe an env setting in tsconfig.json could be a solution...
And I would also appreciate that tsc --init interactively ask for it. Like eslint --init does for example.

@RyanCavanaugh
Copy link
Member

You can set e.g. "lib": ["es2015.core"] in your tsconfig's compilerOptions settings:
image

@yortus
Copy link
Contributor

yortus commented Sep 22, 2016

Why is the browser environment opt-out, but other environments (like node) are opt-in?

@testerez
Copy link
Author

Yes it's working thanks. But now, console cannot be found.
99.9% users will run the javascript code either inside the browser or node.
Don't you think that it would make sense to have simple presets to support those environments ?

@yortus
Copy link
Contributor

yortus commented Sep 22, 2016

Related: #9466

@yortus
Copy link
Contributor

yortus commented Sep 22, 2016

@testerez re getting things like console to work, @RyanCavanaugh's suggestion above doesn't cover that. You also need the node typings. See #9466 (comment). I think the step 3 there is no longer needed due to a recent fix.

@testerez
Copy link
Author

testerez commented Sep 22, 2016

I get this error

error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "noImplicitAny": true,
    "sourceMap": false,
    "strictNullChecks": true,
    "lib": [
      "es2015.core"
    ],
    "types": ["node"]
  }
}

and running
tsc -p tsconfig.json

@yortus
Copy link
Contributor

yortus commented Sep 22, 2016

@testerez try using "lib": ["es2015"] instead of "lib: ["es2015.core"].

@testerez
Copy link
Author

Ho yes sorry didn't see the difference here. Working now!
So what about the interactive tsc --init is there any plan about something like that?

It's not so easy to sell typescript to JS devs... Anything that could make the first contact smoother is welcome!

@yortus
Copy link
Contributor

yortus commented Sep 22, 2016

Personally I agree that typeScript should not 'choose favourites' between environments.

Maybe you could chime in on #9466 since that covers much the same concern and is labeled 'awaiting more feedback'.

@testerez
Copy link
Author

Yes, same topic. Thanks for the link.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 22, 2016

adding a lib for node is covered in #9466. closing.

@mhegazy mhegazy closed this as completed Sep 22, 2016
@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Sep 22, 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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

4 participants