From 5ef968bffe590447cceaeaeb5702b72d43e70460 Mon Sep 17 00:00:00 2001 From: mscharlock Date: Thu, 13 Sep 2018 14:24:21 -0700 Subject: [PATCH] changing folder name --- .../custom-functions-runtime-tests.ts | 32 ++++++++ types/custom-functions-runtime/index.d.ts | 30 +++++++ types/custom-functions-runtime/tsconfig.json | 23 ++++++ types/custom-functions-runtime/tslint.json | 79 +++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 types/custom-functions-runtime/custom-functions-runtime-tests.ts create mode 100644 types/custom-functions-runtime/index.d.ts create mode 100644 types/custom-functions-runtime/tsconfig.json create mode 100644 types/custom-functions-runtime/tslint.json diff --git a/types/custom-functions-runtime/custom-functions-runtime-tests.ts b/types/custom-functions-runtime/custom-functions-runtime-tests.ts new file mode 100644 index 0000000000..d23e2e60e6 --- /dev/null +++ b/types/custom-functions-runtime/custom-functions-runtime-tests.ts @@ -0,0 +1,32 @@ +function ADD10(n: number) { + return n + 10; +} + +declare const CustomFunctionMappings: { + "addTen": ADD10(); +}; + +async function getStockValues(ticker: string, handler: CustomFunctions.StreamingHandler) { + const dollars = await (await fetch(`myService.com/prices/${ticker}`)).json(); + handler.setResult(dollars) +} + +async function getStockValuesOneTime(ticker: string, handler: CustomFunctions.CancelableHandler) { + var 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 diff --git a/types/custom-functions-runtime/index.d.ts b/types/custom-functions-runtime/index.d.ts new file mode 100644 index 0000000000..3bab36de3c --- /dev/null +++ b/types/custom-functions-runtime/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for Custom Functions +// Project: http://dev.office.com +// Definitions by: OfficeDev , Michael Zlatkovsky , Michelle Scharlock +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/* +office-js +Copyright (c) Microsoft Corporation +*/ + +declare const CustomFunctionMappings: { [key: string]: Function }; + +declare namespace CustomFunctions { + interface StreamingHandler 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; + } +} diff --git a/types/custom-functions-runtime/tsconfig.json b/types/custom-functions-runtime/tsconfig.json new file mode 100644 index 0000000000..b3da8763ec --- /dev/null +++ b/types/custom-functions-runtime/tsconfig.json @@ -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", + "office-runtime-tests.ts" + ] +} diff --git a/types/custom-functions-runtime/tslint.json b/types/custom-functions-runtime/tslint.json new file mode 100644 index 0000000000..5c50b51e66 --- /dev/null +++ b/types/custom-functions-runtime/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} \ No newline at end of file