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

ES6 emit missing some typings with lib.d.ts (ES5 typings) #5504

Closed
alexeagle opened this issue Nov 3, 2015 · 4 comments
Closed

ES6 emit missing some typings with lib.d.ts (ES5 typings) #5504

alexeagle opened this issue Nov 3, 2015 · 4 comments
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped

Comments

@alexeagle
Copy link
Contributor

I need to emit non-downlevel ES6 code to feed into another tool in the toolchain.
However, I want to ensure that the project includes only ES5 library code, because there are no runtime polyfills nor does the 6-to-5 tool do any API conversions.

So, I want simply tsc --target es6 --noLib node_modules/typescript/lib/lib.d.ts app.ts
but this doesn't work:

$ ./node_modules/.bin/tsc
error TS2318: Cannot find global type 'Iterable'.
error TS2318: Cannot find global type 'IterableIterator'.
error TS2318: Cannot find global type 'Iterator'.
error TS2318: Cannot find global type 'Symbol'.
error TS2468: Cannot find global value 'Symbol'.

I've followed #4692 but I wonder if there is another answer for this.

Repro
tsconfig.json

    "compilerOptions": {
        "target": "es6",
        "noLib": true,
        "noImplicitAny": false,
        "outDir": "built",
        "rootDir": ".",
        "sourceMap": false
    },
    "exclude": [
        "node_modules"
    ],
    "files": [
        "app.ts",
        "node_modules/typescript/lib/lib.d.ts"
    ]
}

app.ts

let a: string = "hello";
@mhegazy
Copy link
Contributor

mhegazy commented Nov 3, 2015

so you are ok with generators, for..of, lambdas, default and rest args, etc...? if so what is it that you do not want to include? why not Symbol? and Iterables? why not add a custom lib.es6.d.ts then? can you elaborate on what are the other tools you are interpenetrating with?

@alexeagle
Copy link
Contributor Author

we're at Google so of course it's the Closure Compiler. Our internal TS support works like
user's .ts file -> tsc --target es6 -> combine with other closure library files -> closure compiler 6-to-5

So we are constrained to support only the Closure ES6 supported syntax, and disallow any of the runtime APIs. We'll have to use tslint if we find there are unsupported syntax bits that we need to disallow, but right now I'm just focusing on type-checking.

Adding a custom typings file does solve this problem, and it's not long, just a copy of the declarations for those 5 things in the error above. I suppose it would be nice to have

  • that .d.ts file included in the TS distribution, as another shard of the lib.core.es6.d.ts so I don't have to keep my custom file in sync with the place I copied from (like when you add another well-known symbol)
  • and/or some docs on this

@mhegazy
Copy link
Contributor

mhegazy commented Nov 3, 2015

Thanks for the details. #4168 looks like the one you want. we need to find a correct granularity level for the library, and ideally allow for a la cart model of enabling specific parts; we will also need to figure out what it means when that interfere with syntactic features, e.g. what happens if you use for..of in ES6 but do not have Symbol.iterator defined.

To unblock you meantime, the building pieces of the lib file are all in https://github.com/Microsoft/TypeScript/tree/master/src/lib, and you can find how they are combined to generate lib.d.ts, and lib.es6.d.ts in https://github.com/Microsoft/TypeScript/blob/master/Jakefile.js#L163-L171. you should be able to combine the src\lib sources to get the core lib that you need.

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 19, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 19, 2016
@mhegazy mhegazy added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped labels Feb 19, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Apr 4, 2016

This should be fixed by #7715. --lib support should be available now in typescript@next and in the next TypeScript release.

@mhegazy mhegazy closed this as completed Apr 4, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed In Discussion Not yet reached consensus labels Apr 4, 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
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Suggestion An idea for TypeScript @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped
Projects
None yet
Development

No branches or pull requests

3 participants