Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Usage in TypeScript without importing #342

Closed
koltyakov opened this issue Mar 3, 2017 · 3 comments
Closed

Usage in TypeScript without importing #342

koltyakov opened this issue Mar 3, 2017 · 3 comments

Comments

@koltyakov
Copy link
Collaborator

Hi there,

Category

[ ] Enhancement
[ ] Bug
[x] Question

Question

Could you please suggest me with a solution, how to reference sp-pnp-js in typescript project without actual importing the library?

I have sp-pnp-js applied globally in a bundle script within custom action ScriptLink or masterpage, no matter, so it's already on the pages.
There are multiple solutions which use the library, some of them are written in TypeScript and packed with Webpack.

For convenient coding, sp-pnp-js is imported like this:

import { Web } from 'sp-pnp-js';

But, as a result, sp-pnp-js "binaries" are placed to output .js and .map files.

Adding references like:

/// <reference path="./../node_modules/sp-pnp-js/dist/pnp.d.ts" />
// or
/// <reference path="./../node_modules/sp-pnp-js/lib/pnp.d.ts" />

seems like doesn't provide anything to use $pnp.

I ended up with a temporary solution of impoting the lib druring development:

import pnp from 'sp-pnp-js';
declare let $pnp = pnp;

and switching to declaring $pnp variable with any data type and without importing the lib before packing before delivering to the site there $pnp is deployed globally.

declare let $pnp: any;

I wondering, can it be done in more elegant way with referencing (/// <reference path="./../node_modules/sp-pnp-js/dist/pnp.d.ts" />) only approach?

Thanks!

@patrick-rodgers
Copy link
Contributor

This is really a duplicate of #330 and isn't a use case I thought would be very high. I anticipated most folks would want to use the library as an import and then mark it external for builds. But now it has come up twice in a week. There was a limitation in TS that was blocking this but I can't remember what that was now. I will have to go back and find that and see where things stand. Going to close this one as a duplicate - but you can follow #330 for updates.

@koltyakov
Copy link
Collaborator Author

Thanks, Patrick!
Sorry for a duplicate, I really missed this one during a quick search.

@patrick-rodgers
Copy link
Contributor

No worries at all. But since two people brought it up figured worth investigating. If you get a chance try the proposed solution in the other thread #330.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants