-
Notifications
You must be signed in to change notification settings - Fork 233
Ambient Typings #330
Comments
How are you doing your development? VS Code, visual studio? How are you packaging your libraries? |
Just gulp with gulp-typescript and the following tsconfig: {
"compilerOptions": {
"module": "none",
"target": "es5",
"pretty": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noEmitOnError": true,
"noImplicitAny": true,
"sourceMap": true,
"strictNullChecks": true
},
"exclude": [
"node_modules/**/*"
],
"compileOnSave": false,
"buildOnSave": false,
"types": [
"angular",
"jquery",
"lodash"
]
} In the files we use namespaces and links like this |
Ref #88 as well for this investigation. Ref this thread as well. |
Ok, think I have a potential solution here. In your project create a new file called "pnp-global-shim.d.ts" and add the below content and save. You'll need the pnp.d.ts to be in the same folder. /// <reference path="pnp.d.ts" />
export * from "pnp";
export as namespace $pnp; Then in your project this now appears to work: /// <reference path="pnp-global-shim.d.ts" />
$pnp.Logger.subscribe(new $pnp.ConsoleListener());
$pnp.Logger.activeLogLevel = $pnp.LogLevel.Info;
$pnp.sp.web.get().then(w => {
$pnp.Logger.write(JSON.stringify(w));
}); I get the intellisense and I have left the module definition to none. @koltyakov this should work for you as well. Please try that out and if it works we can add that to the build/output process so it will be included in the dist folder moving forward. |
After a quick try, I can confirm that intellisense for $pnp start working (in VSC) with this approach. |
This should work for you, either of these lines: let j: $pnp.Web;
let k = new $pnp.Web("My Url"); |
I have also created a wiki page with these details and will include the shim file in future releases. |
Thank you! |
Category
[ ] Enhancement
[ ] Bug
[x] Question
Hi,
Is there a way to get ambient/global typings? If pnp used without a module system, the typings under https://github.com/SharePoint/PnP-JS-Core/blob/master/dist/pnp.d.ts
I'd like to untegrate pnp globally in a page and compile simple ts-parts without an module system. These parts expect the window variable $pnp (https://github.com/SharePoint/PnP-JS-Core/blob/master/dist/pnp.js#L17) but to compile these parts I need the ambient typing to not have to do something like the following in my own typings.d.ts:
I tried to generate new typings out of the source of PnP-JS-Core ex. with dts-gen (https://github.com/Microsoft/dts-gen) like the following with no success:
Result:
Couldn't load module "sp-pnp-js". Please install it globally (npm install -g sp-pnp-js) and try again.
Some suggestions?
Thanks!
The text was updated successfully, but these errors were encountered: