GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adds 'lib' reference directives by rbuckton · Pull Request #23893 · microsoft/TypeScript

Conversation

@rbuckton

@rbuckton Ron Buckton (rbuckton) commented May 4, 2018

Copy link
Copy Markdown
Contributor

This change adds support for a /// <reference lib="name" /> directive, allowing a file to explicitly include an existing built-in lib file.

  • When a built-in lib is referenced via the lib reference directive, any no-default-lib reference directive in the lib file is ignored. This is so that a lib reference in an imported package won't cause your current project to lose its default lib if you haven't specified one.
  • Built-in lib files are referenced in the same fashion as the "lib" compiler option in tsconfig.json (e.g. use lib="es2015" and not lib="lib.es2015.d.ts", etc.).

In the long term this can help polyfill/shim packages like core-js or es6-shim.

NOTE: Apparently we were very close to running out of heap memory when running gulp tests after running gulp clean as gulp is holding onto too much memory. Individually each task is fine, but in concert they add up to a large amount of uncollected memory. To address this, I've added a script to run some of our builds out-of-process. This is not an issue in the jake builds.

Fixes #15732.
Supersedes #15780

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

styfle reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@rbuckton
Ron Buckton (rbuckton) requested review from a user, Mohamed Hegazy (mhegazy) and Wesley Wigham (weswigham) May 4, 2018 17:50
@rbuckton Ron Buckton (rbuckton) mentioned this pull request May 4, 2018
Add support for 'lib' reference directive #15780
Closed
@ghost ghost mentioned this pull request May 4, 2018
Share code between typeReferenceDirectives and referencedFiles parsing #23904
Closed
ghost
Deleted user (ghost) reviewed May 4, 2018
View reviewed changes
Comment thread src/compiler/parser.ts Outdated
else if (arg.arguments.types) {
typeReferenceDirectives.push({ pos: arg.arguments.types.pos, end: arg.arguments.types.end, fileName: arg.arguments.types.value });
}
else if (arg.arguments.lib) {

@ghost Deleted user (ghost) May 4, 2018

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#23904 Could avoid repeated code here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rbuckton Ron Buckton (rbuckton) May 5, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to do this or do you want to do in your other PR once this is merged?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ghost Deleted user (ghost) May 7, 2018

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll close the other PR since it doesn't have much benefit with only 2 branches, but maybe it would have a benefit with 3 branches, or there's a better way to share the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost ghost mentioned this pull request May 4, 2018
Remove unused interface #23905
Merged
Ron Buckton (rbuckton) added 6 commits May 4, 2018 15:51
@rbuckton
Move getSpellingSuggestion to core
b5540a5
@rbuckton
add libMap and libs exports
c05923b
@rbuckton
Add 'lib' reference support
a089297
@rbuckton
Fork gulp-typescript tasks to run out-of-process
f4ca7ee
@rbuckton
Fix typo in comment
8d230fc
@rbuckton
Accept new symbol baselines, ensure expected ordering for default libs
68c0e52
@rbuckton
Ron Buckton (rbuckton) force-pushed the libReference branch from ce2f777 to 68c0e52 Compare May 5, 2018 00:24
ghost
Deleted user (ghost) reviewed May 8, 2018
View reviewed changes
Comment thread tests/baselines/reference/arrayFrom.types
>Array.from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
>Array : ArrayConstructor
>from : { <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
>from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }

@ghost Deleted user (ghost) May 8, 2018

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't arrayFrom.ts have a Set test? Then if would break due to this change since Set is Iterable but not ArrayLike.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rbuckton Ron Buckton (rbuckton) May 9, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a test, but this shouldn't break because there is still an overload that supports Iterable. The order just changed because I cleaned up the default order of libs. Previously if you had a "lib": ["es5", "es2015"] in your tsconfig.json we would actually end up inserting them in reverse order because we were doing files.unshift for default libs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rbuckton
Add additional Array.from test case
6c35abe
@rbuckton
Ron Buckton (rbuckton) force-pushed the libReference branch from 7d5c1bc to 99cb2ad Compare May 9, 2018 18:40
@rbuckton
Merge branch 'master' into libReference
698f229
@rbuckton
Ron Buckton (rbuckton) force-pushed the libReference branch from 99cb2ad to 698f229 Compare May 9, 2018 18:41
@rbuckton
Merge branch 'master' into libReference
8548fb8
@NN---

NN (NN---) commented May 20, 2018

Copy link
Copy Markdown

Will this allow fixing #16077 ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton Ron Buckton (rbuckton) mentioned this pull request May 25, 2018
Remove dependency on types not in ES5 DefinitelyTyped/DefinitelyTyped#25882
Merged
@rbuckton
Merge branch 'master' into libReference
ec0af20
ghost
Deleted user (ghost) reviewed May 29, 2018
View reviewed changes
Comment thread src/compiler/core.ts Outdated

@ghost Deleted user (ghost) May 29, 2018

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mhegazy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@rbuckton Ron Buckton (rbuckton) May 30, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what caused that to change, but I'll revert.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 30, 2018
View reviewed changes
Comment thread src/compiler/commandLineParser.ts Outdated
// Internally we add some additional lib references that we only support when used as part of a
// "lib" reference directive. They are not available on the command line or in tsconfig.json.
/* @internal */
export const libMap = cloneMap(commandLineLibMap)

@mhegazy Mohamed Hegazy (mhegazy) May 30, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would just add this to the map. chances are no one will ever include it.. and if they did.. it does not break anything.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rbuckton reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 30, 2018
View reviewed changes
Comment thread src/lib/es2015.full.d.ts Outdated
@@ -0,0 +1,14 @@
/// <reference lib="es5" />

@mhegazy Mohamed Hegazy (mhegazy) May 30, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not this just be:

/// <reference lib="es2015" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rbuckton reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 30, 2018
View reviewed changes
Comment thread src/lib/esnext.full.d.ts
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" /> No newline at end of file

@mhegazy Mohamed Hegazy (mhegazy) May 30, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. i would move this just after dom

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 30, 2018
View reviewed changes
Comment thread src/lib/webworker.generated.d.ts Outdated
@@ -1,3 +1,5 @@
/// <reference lib="webworker.importscripts" />

@mhegazy Mohamed Hegazy (mhegazy) May 30, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed here, the file is autogenerated, and it already has the correct definition. we add it to lib.d.ts to partially allow the lib to be used in webworkers for simple cases..

the two files dom and webworker have too many conflicts in between them, and can not be loaded together in the same context anyways..

so I would just revert the changes to this file, and leave it as is.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rbuckton reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 30, 2018
View reviewed changes
Comment thread src/lib/libs.json
"es5.full": "lib.d.ts",
"es2015.full": "lib.es6.d.ts"
},
"sources": {

@mhegazy Mohamed Hegazy (mhegazy) May 30, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the support for sources from jake and gulp as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 30, 2018
View reviewed changes
Comment thread src/compiler/commandLineParser.ts Outdated
/* @internal */
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };

// NOTE: The order here is important to default lib ordering

@mhegazy Mohamed Hegazy (mhegazy) May 30, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would expand on this comment and say that the order of the list here is the same order the lib files have in the generated program, and add a note to see use in createProgram

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Ron Buckton (rbuckton) added 3 commits May 31, 2018 10:02
@rbuckton
Merge branch 'master' into libReference
b4e113b
@rbuckton
Fix preProcessFile tests
cee2920
@rbuckton
Updated baselines
159e73c
mhegazy
Mohamed Hegazy (mhegazy) reviewed May 31, 2018
View reviewed changes
Comment thread src/services/goToDefinition.ts Outdated
}

export function getReferenceAtPosition(sourceFile: SourceFile, position: number, program: Program): { fileName: string, file: SourceFile } | undefined {
debugger;

@mhegazy Mohamed Hegazy (mhegazy) May 31, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

styfle reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
mhegazy
Mohamed Hegazy (mhegazy) approved these changes May 31, 2018
View reviewed changes

@mhegazy Mohamed Hegazy (mhegazy) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one debugger statement that needs to be removed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Ron Buckton (rbuckton) added 2 commits June 4, 2018 13:42
@rbuckton
Remove debugger statement
fb09aeb
@rbuckton
Merge branch 'master' into libReference
6668412
@rbuckton
Ron Buckton (rbuckton) merged commit fbeb58a into master Jun 4, 2018
@styfle

Steven (styfle) commented Jun 4, 2018

Copy link
Copy Markdown
Contributor

Great job with this PR!

The diff won't load for me so I'll just ask here 🤔 ...

Does this PR actually implement <reference lib> in such a way to make the TS engine smaller? Or is this PR just implementing the feature itself and the usage will be implemented in a different PR?

For more context see: #23339 (comment)

Thanks! 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy
Mohamed Hegazy (mhegazy) deleted the libReference branch June 5, 2018 00:03
@mhegazy

Mohamed Hegazy (mhegazy) commented Jun 5, 2018

Copy link
Copy Markdown
Contributor

lib folder should go down by 4 MB or so.

styfle and Swatinem reacted with hooray emoji
All reactions
  • 🎉 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost mentioned this pull request Jun 5, 2018
runtests-browser cause heap out of memory error #24697
Closed
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Jun 5, 2018

Copy link
Copy Markdown
Member

Mohamed Hegazy (@mhegazy) Ron Buckton (@rbuckton) This is going to be a big break to API consumers loading just lib.d.ts from the TS and expecting things to work - what's the mitigation here for APIs loading e.g. a fixed set of files from the network on load?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Jun 5, 2018

Copy link
Copy Markdown
Member

You could always just use an older copy of the lib, if you're one of those API consumers. We ship the latest one with the latest features for consumers, but if you have constraints that force you to, usually you can just include an older copy of the lib in your project - a bunch of our older RWC tests do that.

mhegazy reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Jun 6, 2018

Copy link
Copy Markdown
Contributor

If we get feedback on that we can ship an all in one file as well. The biggest issue is tool authors really, like TS-loader for instance. Most users use the built in lib with no changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Bnaya

Bnaya Peretz (Bnaya) commented Jun 9, 2018

Copy link
Copy Markdown

Will it add the library to the entire program or only from the reference point and downward?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Jun 11, 2018

Copy link
Copy Markdown
Contributor

not sure i understand the question. the only difference is instead of on file lib.d.ts you will have a set of them in your program.

Bnaya reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Jun 13, 2018

Copy link
Copy Markdown
Member

Ron Buckton (@rbuckton) Mohamed Hegazy (@mhegazy) this has broken our own build because buildProtocol builds up its program with --noResolve. Checking out fbeb58a and running jake LKG twice fails.

Now noResolve effectively means you don't load any standard library types at all, which will be visible to more than just API consumers.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ericdrobinson Eric Robinson (ericdrobinson) mentioned this pull request Jun 13, 2018
Add es3.d.ts #16077
Closed
@mhegazy

Mohamed Hegazy (mhegazy) commented Jun 13, 2018

Copy link
Copy Markdown
Contributor

Looks like we need to ignore noResolve when we are resolving lib files as well.. we already have a ignoreNoDefaultLib flag, so we can extend this to mean resolvingLibReference and ignore noResolve as well as noDefaultLib

RyanCavanaugh reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Jun 13, 2018

Copy link
Copy Markdown
Member

--disableIgnoreSkipNoResolve

mhegazy, Bnaya, and styfle reacted with laugh emoji
All reactions
  • 😄 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Jun 13, 2018

Copy link
Copy Markdown
Contributor Author

I'll take a look. Lib refs are supposed to ignore noResolve.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Jun 13, 2018

Copy link
Copy Markdown
Contributor Author

This had nothing to do with noResolve and more to do with buildProtocol.ts looking only ignoring "lib.d.ts". It also looks like its already fixed in master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost ghost mentioned this pull request Jun 19, 2018
Compiler options have different effects on command line vs in fourslash test #25081
Closed
@timocov Evgeniy Timokhov (timocov) mentioned this pull request Jun 29, 2018
Fix detecting TypeScript default lib files timocov/dts-bundle-generator#48
Merged
@brikou Brice BERNARD (brikou) mentioned this pull request Sep 12, 2018
feat: remove dom dependency graffle-js/graffle#108
Merged
@ghost ghost mentioned this pull request Oct 8, 2018
@types/[email protected] throws Error: Cannot find name 'Set' DefinitelyTyped/DefinitelyTyped#28969
Closed
4 tasks done
This was referenced Feb 8, 2019
Availability of Node Slack SDK v5 (timeline for end of support on v4) slackapi/node-slack-sdk#689
Closed
Update to TypeScript 3.3 slackapi/node-slack-sdk#693
Closed
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@weswigham Wesley Wigham (weswigham) Awaiting requested review from weswigham
2 more reviewers
@mhegazy Mohamed Hegazy (mhegazy) mhegazy approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Suggestion: Add "lib" reference directive

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@rbuckton @NN--- @mhegazy @styfle @RyanCavanaugh @weswigham @Bnaya
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.