Skip to content

skipDefaultLibCheck doesn't work with noLib #5510

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
alexeagle opened this issue Nov 3, 2015 · 5 comments
Closed

skipDefaultLibCheck doesn't work with noLib #5510

alexeagle opened this issue Nov 3, 2015 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@alexeagle
Copy link
Contributor

We rely on the performance improvement of skipping type-checking of lib.d.ts.
But, as I described in #5504 our setup is to emit ES6 while using the types from lib.d.ts. (es5).

It seems that if I pass the lib.d.ts on the command line, rather than rely on the auto-loading behavior, then the isDefaultLib argument is always false, here:
https://github.com/Microsoft/TypeScript/blob/v1.6.2/src/compiler/program.ts#L371

So that means it's slow again:

alexeagle-macbookpro2:test123 alexeagle$ time ./node_modules/.bin/tsc -p targetES6
real    0m0.696s
user    0m0.835s
sys 0m0.050s
alexeagle-macbookpro2:test123 alexeagle$ time ./node_modules/.bin/tsc -p targetES6
real    0m0.703s
user    0m0.846s
sys 0m0.049s
alexeagle-macbookpro2:test123 alexeagle$ time ./node_modules/.bin/tsc -p targetES5
real    0m0.375s
user    0m0.443s
sys 0m0.033s
alexeagle-macbookpro2:test123 alexeagle$ time ./node_modules/.bin/tsc -p targetES5
real    0m0.379s
user    0m0.441s
sys 0m0.035s

Could that hardcoded false be changed to a predicate of whether the file passed is known to be a standard lib (either with the /// <reference no-default-lib="true"/> pragma or because the path matches compilerHost#getDefaultLibFileName)?

Here's the repro directory:

alexeagle-macbookpro2:test123 alexeagle$ find target* -type f -print -exec cat {} \;
targetES5/app.ts
let a: string = "hello";
targetES5/built/app.js
var a = "hello";
targetES5/tsconfig.json
{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "skipDefaultLibCheck": true,
        "noImplicitAny": false,
        "outDir": "built",
        "rootDir": ".",
        "sourceMap": false
    },
    "exclude": [
        "node_modules"
    ]
}
targetES6/app.ts
let a: string = "hello";
targetES6/built/app.js
let a = "hello";
targetES6/lib.es6-emit.d.ts
/**
 * @fileoverview a subset of typings from lib.core.es6.d.ts which are required
 * for the compiler to emit ES6 code, even though we only allow ES5 API usage.
 * This custom typing is a suggested workaround for
 * https://github.com/Microsoft/TypeScript/issues/5504
 */

interface IteratorResult<T> {
    done: boolean;
    value?: T;
}

interface Iterator<T> {
    next(value?: any): IteratorResult<T>;
    return?(value?: any): IteratorResult<T>;
    throw?(e?: any): IteratorResult<T>;
}

interface Iterable<T> {
    [Symbol.iterator](): Iterator<T>;
}

interface IterableIterator<T> extends Iterator<T> {
    [Symbol.iterator](): IterableIterator<T>;
}

interface Symbol {
    /** Returns a string representation of an object. */
    toString(): string;

    /** Returns the primitive value of the specified object. */
    valueOf(): Object;

    [Symbol.toStringTag]: string;
}

interface SymbolConstructor {
    /**
      * A reference to the prototype.
      */
    prototype: Symbol;

    /**
      * Returns a new unique Symbol value.
      * @param  description Description of the new Symbol object.
      */
    (description?: string|number): symbol;

    /**
      * Returns a Symbol object from the global symbol registry matching the given key if found.
      * Otherwise, returns a new symbol with this key.
      * @param key key to search for.
      */
    for(key: string): symbol;

    /**
      * Returns a key from the global symbol registry matching the given Symbol if found.
      * Otherwise, returns a undefined.
      * @param sym Symbol to find the key for.
      */
    keyFor(sym: symbol): string;

    // Well-known Symbols

    /**
      * A method that determines if a constructor object recognizes an object as one of the
      * constructor’s instances. Called by the semantics of the instanceof operator.
      */
    hasInstance: symbol;

    /**
      * A Boolean value that if true indicates that an object should flatten to its array elements
      * by Array.prototype.concat.
      */
    isConcatSpreadable: symbol;

    /**
      * A method that returns the default iterator for an object. Called by the semantics of the
      * for-of statement.
      */
    iterator: symbol;

    /**
      * A regular expression method that matches the regular expression against a string. Called
      * by the String.prototype.match method.
      */
    match: symbol;

    /**
      * A regular expression method that replaces matched substrings of a string. Called by the
      * String.prototype.replace method.
      */
    replace: symbol;

    /**
      * A regular expression method that returns the index within a string that matches the
      * regular expression. Called by the String.prototype.search method.
      */
    search: symbol;

    /**
      * A function valued property that is the constructor function that is used to create
      * derived objects.
      */
    species: symbol;

    /**
      * A regular expression method that splits a string at the indices that match the regular
      * expression. Called by the String.prototype.split method.
      */
    split: symbol;

    /**
      * A method that converts an object to a corresponding primitive value.
      * Called by the ToPrimitive abstract operation.
      */
    toPrimitive: symbol;

    /**
      * A String value that is used in the creation of the default string description of an object.
      * Called by the built-in method Object.prototype.toString.
      */
    toStringTag: symbol;

    /**
      * An Object whose own property names are property names that are excluded from the 'with'
      * environment bindings of the associated objects.
      */
    unscopables: symbol;
}
declare var Symbol: SymbolConstructor;
targetES6/tsconfig.json
{
    "compilerOptions": {
        "target": "es6",
        "skipDefaultLibCheck": true,
        "noLib": true,
        "noImplicitAny": false,
        "outDir": "built",
        "rootDir": ".",
        "sourceMap": false
    },
    "files": [
        "app.ts",
        "lib.es6-emit.d.ts",
        "../node_modules/typescript/lib/lib.d.ts"
    ]
}

cc @mprobst

@DanielRosenwasser DanielRosenwasser added the Suggestion An idea for TypeScript label Nov 3, 2015
@DanielRosenwasser
Copy link
Member

Could that hardcoded false be changed to a predicate of whether the file passed is known to be a standard lib (either with the /// <reference no-default-lib="true"/> pragma

That was originally the plan for --skipDefaultLibCheck, but I think we wanted to avoid overloading the utility of the flag. Additionally, since --skipDefaultLibCheck was originally used for running our tests and one of our test files is the TypeScript 1.0 lib.d.ts file, we were running into complications with running it.

@DanielRosenwasser
Copy link
Member

@alexeagle I opened #5511; if you'd like to try to pull down that branch and let us know if you get a speedup, we'd appreciate it.

@mhegazy mhegazy added Bug A bug in TypeScript and removed Suggestion An idea for TypeScript labels Nov 3, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Nov 3, 2015
@alexeagle
Copy link
Contributor Author

Thanks for picking that up Daniel. I'll give it a try when Mohamed is done
changing it :)
For now we'll have to use a workaround since we are trying to depend only
on released version of TS

On Tue, Nov 3, 2015 at 1:03 PM Daniel Rosenwasser [email protected]
wrote:

@alexeagle https://github.com/alexeagle I opened #5511
#5511; if you'd like to try
to pull down that branch and let us know if you get a speedup, we'd
appreciate it.


Reply to this email directly or view it on GitHub
#5510 (comment)
.

@mhegazy mhegazy added Fixed in TSJS repo Fixed A PR has been merged for this issue and removed Fixed in TSJS repo labels Nov 10, 2015
@mhegazy mhegazy closed this as completed Nov 10, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Nov 10, 2015

should be in typescript@next later tonight.

@alexeagle
Copy link
Contributor Author

Thanks!

On Mon, Nov 9, 2015 at 4:05 PM Mohamed Hegazy [email protected]
wrote:

should be in typescript@next later tonight.


Reply to this email directly or view it on GitHub
#5510 (comment)
.

@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants