From ce4df95708c928eec02ca1bcbbfedc7327481e54 Mon Sep 17 00:00:00 2001 From: Roman Charugin Date: Tue, 20 Aug 2019 00:05:44 +0300 Subject: [PATCH] Add types for scroll (#37592) * Add types for scroll * Remove tslint-rules and change version of the target * Fix linter errors --- types/scroll/index.d.ts | 45 ++++++++++++++++++++++++++++++++++++ types/scroll/scroll-tests.ts | 23 ++++++++++++++++++ types/scroll/tsconfig.json | 24 +++++++++++++++++++ types/scroll/tslint.json | 3 +++ 4 files changed, 95 insertions(+) create mode 100644 types/scroll/index.d.ts create mode 100644 types/scroll/scroll-tests.ts create mode 100644 types/scroll/tsconfig.json create mode 100644 types/scroll/tslint.json diff --git a/types/scroll/index.d.ts b/types/scroll/index.d.ts new file mode 100644 index 0000000000..8f2202d125 --- /dev/null +++ b/types/scroll/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for scroll 3.0 +// Project: https://github.com/michaelrhodes/scroll +// Definitions by: Roman Charugin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type ScrollError = Error | null; + +interface ScrollOptions { + /** + * Ease function + * @default easeInOut + */ + ease?: (time: number) => number; + /** + * Animation duration + * @default 350 + */ + duration?: number; +} + +interface ScrollCallback { + (error: ScrollError, value: number): void; +} + +interface Cancel { + (): void; +} + +interface Scroll { + /** + * @param el Element to scroll + * @param to Scroll to value + * @param opts Additional options + * @param cb Callback function to call after + * @return Function to stop scrolling + */ + (el: HTMLElement, to: number, opts?: ScrollOptions | ScrollCallback, cb?: ScrollCallback): Cancel; +} + +declare const scroll: { + left: Scroll; + top: Scroll; +}; + +export = scroll; diff --git a/types/scroll/scroll-tests.ts b/types/scroll/scroll-tests.ts new file mode 100644 index 0000000000..390a72d3b9 --- /dev/null +++ b/types/scroll/scroll-tests.ts @@ -0,0 +1,23 @@ +import scroll = require('scroll'); + +const el: HTMLElement = document.createElement('div'); +const opts = { + duration: 1000, + ease: (time: number) => 0.5 * time, +}; +const cb: (error: Error | null, scrollValue: number) => void = (error, scrollValue) => { + if (error != null) { + console.error(error); + } else { + console.log('scrolling completed! current scroll position is ', scrollValue); + } +}; + +scroll.left(el, 500, opts, cb); +scroll.top(el, 500, opts, cb); + +scroll.left(el, 500, opts); +scroll.top(el, 500, opts); + +scroll.left(el, 500, cb); +scroll.top(el, 500, cb); diff --git a/types/scroll/tsconfig.json b/types/scroll/tsconfig.json new file mode 100644 index 0000000000..70e091b47e --- /dev/null +++ b/types/scroll/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "scroll-tests.ts" + ] +} \ No newline at end of file diff --git a/types/scroll/tslint.json b/types/scroll/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/scroll/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}