Merge pull request #28903 from mscharlock/customfunctions

Adding custom-functions-runtime type
This commit is contained in:
Nathan Shively-Sanders
2018-09-19 08:29:56 -07:00
committed by GitHub
4 changed files with 92 additions and 0 deletions
@@ -0,0 +1,33 @@
/* Note that this is a sample function for the purpose of running the below CustomFunctionsMappings test */
function ADD10(n: number) {
return n + 10;
}
CustomFunctionMappings = {
addTen: ADD10
};
async function getStockValues(ticker: string, handler: CustomFunctions.StreamingHandler<number>) {
const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json();
handler.setResult(dollars);
}
async function getStockValuesOneTime(ticker: string, handler: CustomFunctions.CancelableHandler) {
let shouldStop = false;
handler.onCanceled = () => shouldStop = true;
await pause(1000);
if (shouldStop) {
return null;
}
const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json();
return dollars;
}
async function getStockValuesNowWithNoCancelling(ticker: string) {
const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json();
return dollars;
}
declare function pause(ms: number): Promise<void>;
+30
View File
@@ -0,0 +1,30 @@
// Type definitions for Custom Functions 1.4
// Project: http://dev.office.com
// Definitions by: OfficeDev <https://github.com/OfficeDev>, Michael Zlatkovsky <https://github.com/Zlatkovsky>, Michelle Scharlock <https://github.com/mscharlock>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/*
office-js
Copyright (c) Microsoft Corporation
*/
declare let CustomFunctionMappings: { [key: string]: Function };
declare namespace CustomFunctions {
interface StreamingHandler<T> extends CancelableHandler {
/*
* Sets the returned result for a streaming custom function.
* @beta
*/
setResult: (value: T) => void;
}
interface CancelableHandler {
/*
* Handles what should occur when a custom function is canceled.
* @beta
*/
onCanceled: () => void;
}
}
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"target": "es6"
},
"files": [
"index.d.ts",
"custom-functions-runtime-tests.ts"
]
}
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false
}
}