From 709b3f90c21ef14fd4b9263258fa54b067cc557d Mon Sep 17 00:00:00 2001 From: David Mendez Date: Tue, 16 May 2017 12:27:48 -0400 Subject: [PATCH] docs(@angular/cli): Updates global library instructions --- docs/documentation/stories/global-scripts.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/documentation/stories/global-scripts.md b/docs/documentation/stories/global-scripts.md index 4a16da093d94..fe12d7473e03 100644 --- a/docs/documentation/stories/global-scripts.md +++ b/docs/documentation/stories/global-scripts.md @@ -32,12 +32,25 @@ global library, and one imported as a module. This is especially bad for libraries with plugins, like JQuery, because each copy will have different plugins. -Instead, download typings for your library (`npm install @types/jquery`) which will give you -access to the global variables exposed by that library. +Instead, download typings for your library (`npm install @types/jquery`) and follow +the [3rd Party Library Installation](https://github.com/angular/angular-cli/wiki/stories-third-party-lib) steps, +this will give you access to the global variables exposed by that library. If the global library you need to use does not have global typings, you can also declare them manually in `src/typings.d.ts` as `any`: ``` declare var libraryName: any; -``` \ No newline at end of file +``` + +When working with scripts that extend other libraries, for instance with JQuery plugins +(e.g, `$('.test').myPlugin();`), since the installed `@types/jquery` may not include `myPlugin`, +you would need to add an interface like the one below in `src/typings.d.ts`. + +``` +interface JQuery { + myPlugin(options?: any): any; +} +``` + +Otherwise you may see `[TS][Error] Property 'myPlugin' does not exist on type 'JQuery'.` in your IDE.