This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.resolve().then(function () { return require(/* webpackChunkName: "momentjs" */ "moment"); }).then(function (moment) { | |
// lazyModule has all of the proper types, autocomplete works, | |
// type checking works, code references work \o/ | |
var time = moment().format(); | |
console.log("TypeScript >= 2.4.0 Dynamic Import Expression:"); | |
console.log(time); | |
_this.setState({ time: time }); | |
}) | |
.catch(function (err) { | |
console.log("Failed to load moment", err); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "commonjs", | |
//.... more | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import(/* webpackChunkName: "momentjs" */ "moment") | |
.then((moment) => { | |
// lazyModule has all of the proper types, autocomplete works, | |
// type checking works, code references work \o/ | |
const time = moment().format(); | |
console.log("TypeScript >= 2.4.0 Dynamic Import Expression:"); | |
console.log(time); | |
this.setState({ time }); | |
}) | |
.catch((err) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("*************************************************************"); | |
console.log("*** Document Collection using as(MyDocumentCollection) and get() with Custom Array Parser"); | |
console.log("*************************************************************"); | |
const myDocumentsWithCustomObjectAsDocumentsGetParser: any[] = await pnp.sp | |
.web | |
.lists | |
.getByTitle(libraryName) | |
.items | |
// using as("Model") overrides select and expand queries | |
.as(MyDocumentCollection) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("#############################"); | |
console.log("# Query only one document #"); | |
console.log("#############################"); | |
console.log("*************************************************************"); | |
console.log("*** One document selecting all properties"); | |
console.log("*************************************************************"); | |
const myDocument: any = await pnp.sp | |
.web | |
.lists | |
.getByTitle(libraryName) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("*************************************************************"); | |
console.log("*** Document Collection using as(MyDocumentCollection) and get() with Custom Array Parser"); | |
console.log("*************************************************************"); | |
const myDocumentsWithCustomObjectAsDocumentsGetParser: any[] = await pnp.sp | |
.web | |
.lists | |
.getByTitle(libraryName) | |
.items | |
// using as("Model") overrides select and expand queries | |
.as(MyDocumentCollection) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("*************************************************************"); | |
console.log("*** Document Collection using as(MyDocumentCollection) and get() with Custom Array Parser returning only properties with @select"); | |
console.log("*************************************************************"); | |
const myDocumentsWithCustomObjectAsDocumentsGetParserJustSelect: any[] = await pnp.sp | |
.web | |
.lists | |
.getByTitle(libraryName) | |
.items | |
// using as("Model") overrides select and expand queries | |
.as(MyDocumentCollection) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("*************************************************************"); | |
console.log("*** One document using select, expand and get() with MyDocument Custom Parser"); | |
console.log("*************************************************************"); | |
const myDocumentWithSelectExpandGetParser: any = await pnp.sp | |
.web | |
.lists | |
.getByTitle(libraryName) | |
.items | |
.getById(1) | |
.select("Title", "FileLeafRef", "File/Length") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ODataParserBase, QueryableConstructor, Util, Logger, LogLevel } from "sp-pnp-js"; | |
import { getEntityUrl } from "sp-pnp-js/lib/sharepoint/odata"; | |
import { getSymbol } from "../utils/symbol"; | |
/** | |
* Custom Response Array Parser to be integrated with @select and @expand decorators | |
* It can be used on PnP Core JS get() method as a parameter | |
*/ | |
export class SelectDecoratorsArrayParser<T> extends ODataParserBase<T[]> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import models | |
import { MyDocument } from "../model/MyDocument"; | |
import { MyDocumentCollection } from "../model/MyDocumentCollection"; | |
// import pnp js | |
import pnp from "sp-pnp-js"; | |
console.log("*************************************************************"); | |
console.log("*** Document Collection using as(MyDocumentCollection) and get()"); | |
console.log("*************************************************************"); |