Add types for scroll (#37592)

* Add types for scroll

* Remove tslint-rules and change version of the target

* Fix linter errors
This commit is contained in:
Roman Charugin 2019-08-20 00:05:44 +03:00 committed by Sheetal Nandi
parent 0069742408
commit ce4df95708
4 changed files with 95 additions and 0 deletions

45
types/scroll/index.d.ts vendored Normal file
View File

@ -0,0 +1,45 @@
// Type definitions for scroll 3.0
// Project: https://github.com/michaelrhodes/scroll
// Definitions by: Roman Charugin <https://github.com/romic>
// 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;

View File

@ -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);

View File

@ -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"
]
}

3
types/scroll/tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}