-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
using noLib results in a number of intrinsic errors on empty file #3930
Comments
yeah, that's the idea of |
I can see where my question could cause confusion, let me clarify. I understand that using --noLib means that lib.*.d.ts isn't imported. My question stems more from the fact that there are errors reported even though no code, for instance, uses To put it another way, there is (apparently) a rule somewhere that in order for an application to run without errors, even if that application is completely empty, |
That's correct. |
Thanks. |
|
Why would you have to put this in every source file? The "flag" you're describing is equivalent to |
Thx Ryan - but I'm a bit unclear as to how to go about 'adding the path to the lib.d.ts file you want'? Can you show an example invocation of 'tsc' that uses lib.core.d.ts in conjunction with a --noLib flag?
Of course, |
Aha - I was thinking 'path' as in 'java classpath', but it turns out that adding the lib.core.d.ts as one of the files to be compiled works. So the solution that worked for me is:
|
This makes it hard to compile programs in the browser using the Compiler API. Do I really need to fetch a copy of lib.core.d.ts using AJAX to feed it to the compiler? I'm not using any of those "global types" in the code I'm writing in the browser. |
I agree that that's how things have been implemented. But I think we could be a little more lax. We could make it so that these types are loaded on demand, and you only get the error once you hit a type that you need that isn't defined. Or, one way you could think about it was that there was always a file included with things like: interface Object { }
interface String { }
interface Number { } But that might be bad because how we'd have no structural checks at all. That said, maybe there isn't a lot of value for either of these. Using no-lib and not providing definitions for these types seems like a very uncommon thing to do. |
@binarez it depends on what you want to do. if you want to show semantic errors, i.e. errors you would get from the compiler compiling on the command line, then you need the library file, other wise you will not get the correct errors. if, however, all you need is to get the output, i.e. transpiled JS, use it would help if you can shed some light on what you are trying to do, then we can help you more. |
It would be good if everything would be inside one namespace/module. The namespace/module could be System, like in .Net. For example System.Array. Then if you have own class Array in your code it will not mess with System.Array. |
Keep in mind that when using this option we may get errors on empty files. microsoft/TypeScript#3930
This may bring errors in empty files. microsoft/TypeScript#3930
This may be intended but wanted to bring it up for discussion. If I create an empty TypeScript file and call
tsc app.ts
everything is fine, but if I usetsc app.ts --noLib
I see:error TS2318: Cannot find global type 'Array'.
error TS2318: Cannot find global type 'Boolean'.
error TS2318: Cannot find global type 'Function'.
error TS2318: Cannot find global type 'IArguments'.
error TS2318: Cannot find global type 'Number'.
error TS2318: Cannot find global type 'Object'.
error TS2318: Cannot find global type 'RegExp'.
error TS2318: Cannot find global type 'String'.
So is the intention that if you use --noLib you must specify your own lib file that declares these items as a bare minimum?
The text was updated successfully, but these errors were encountered: