You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
using noLib results in a number of intrinsic errors on empty file #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 use tsc 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?
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 Boolean or Number.
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, interface Number {}, etc must exist, and I'm just trying to verify that's the intended behavior.
Is there an 'minimum-lib.d.ts' available that has the minimum declarations to avoid the noisy TS 2318 errors when using the --noLib flag? Or should we just mine the lib.d.ts for the above 8 global types?
Is there a way to specify 'use minimum-lib.d.ts' as a compiler flag? If not, I assume we have to manually put a ///<reference path="../../../defs/minimum-lib.d.ts" /> in every ts source file that uses one of the builtin types. (and compiling third-party libs/src will still generate the noisy TS2318 errors).
Is there an 'minimum-lib.d.ts' available that has the minimum declarations
src\lib\core.d.ts isn't fully minimal, but is much smaller than the full lib.d.ts
Is there a way to specify 'use minimum-lib.d.ts' as a compiler flag? If not, I assume we have to manually put a /// in every ts source file that uses one of the builtin types.
Why would you have to put this in every source file? The "flag" you're describing is equivalent to --noLib plus adding the path to the lib.d.ts file you want to the list of files you put on the commandline
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?
In other words, here is my 1.5.3 experiment:
touch foo.ts
tsc --noLib foo.ts // get TS 2318 errors, so how do I get lib.core.d.ts in the 'path'?
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:
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.
Stéphane Duguay (@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.
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.
Activity
adidahiya commentedon Jul 20, 2015
yeah, that's the idea of
--noLib. it allows you to manually import the relevant lib.*.d.ts file for your project's environment rather than the default compilerlib.d.ts: https://github.com/Microsoft/TypeScript/tree/master/binjbrantly commentedon Jul 20, 2015
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
BooleanorNumber.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,
interface Number {}, etc must exist, and I'm just trying to verify that's the intended behavior.RyanCavanaugh commentedon Jul 20, 2015
That's correct.
jbrantly commentedon Jul 21, 2015
Thanks.
ilbmiller commentedon Jul 21, 2015
RyanCavanaugh commentedon Jul 21, 2015
src\lib\core.d.tsisn't fully minimal, but is much smaller than the fulllib.d.tsWhy would you have to put this in every source file? The "flag" you're describing is equivalent to
--noLibplus adding the path to the lib.d.ts file you want to the list of files you put on the commandlineilbmiller commentedon Jul 21, 2015
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?
In other words, here is my 1.5.3 experiment:
Of course,
tsc foo.tsworks just fine.ilbmiller commentedon Jul 21, 2015
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:
binarez commentedon Nov 3, 2015
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.
CyrusNajmabadi commentedon Nov 3, 2015
Ryan Cavanaugh (@RyanCavanaugh)
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:
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.
mhegazy commentedon Nov 3, 2015
Stéphane Duguay (@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
ts.transpileinstead, this does not require any semantic information, and no need for the library. see https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#a-simple-transform-function for more details.it would help if you can shed some light on what you are trying to do, then we can help you more.
aturpeinen commentedon Dec 28, 2015
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.
[chore:revert] forget using lib
[chore:revert] do not use lib in tsconfig