mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Merge pull request #28903 from mscharlock/customfunctions
Adding custom-functions-runtime type
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user