mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-14 14:00:26 +00:00
Add types for cycled
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import Cycled = require('cycled');
|
||||
|
||||
const cycled = new Cycled([1, 2, 3]);
|
||||
// $ExpectType Cycled<number>
|
||||
cycled;
|
||||
|
||||
// $ExpectType number
|
||||
cycled.index;
|
||||
cycled.index = 1;
|
||||
|
||||
// $ExpectType number
|
||||
cycled.current();
|
||||
|
||||
// $ExpectType number
|
||||
cycled.next();
|
||||
|
||||
// $ExpectType number
|
||||
cycled.previous();
|
||||
|
||||
// $ExpectType number
|
||||
cycled.step(10);
|
||||
|
||||
// $ExpectType Iterator<number>
|
||||
cycled.indefinitely();
|
||||
|
||||
// $ExpectType Iterator<number>
|
||||
cycled.indefinitelyReversed();
|
||||
|
||||
// $ExpectType number[]
|
||||
[...cycled];
|
||||
|
||||
class TabComponent {
|
||||
views: Cycled<string>;
|
||||
activeView: string;
|
||||
|
||||
constructor(views: string[]) {
|
||||
this.activeView = views[0];
|
||||
this.views = new Cycled(views);
|
||||
}
|
||||
|
||||
setActiveView(view: string) {
|
||||
this.activeView = view;
|
||||
this.views.index = this.views.indexOf(view);
|
||||
}
|
||||
|
||||
nextView() {
|
||||
this.setActiveView(this.views.next());
|
||||
}
|
||||
|
||||
previousView() {
|
||||
this.setActiveView(this.views.previous());
|
||||
}
|
||||
}
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
// Type definitions for cycled 1.0
|
||||
// Project: https://github.com/sindresorhus/cycled#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = Cycled;
|
||||
|
||||
// tslint:disable:jsdoc-format
|
||||
declare class Cycled<T> extends Array<T> {
|
||||
/**
|
||||
* Initiates an array subclass with the methods documented below.
|
||||
* Since it's an array, you can use all the normal array methods on it.
|
||||
*
|
||||
* The instance is an iterable that will cycle through the array.
|
||||
* It will cycle through the number of elements equaling the length of the array from the current index.
|
||||
* ```
|
||||
const numberCycle = new Cycled([1,2,3,4,5]);
|
||||
|
||||
console.log(...numberCycle);
|
||||
//=> 1 2 3 4 5
|
||||
```
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
constructor(input: T[]);
|
||||
|
||||
/**
|
||||
* Get or set the current index.
|
||||
*/
|
||||
index: number;
|
||||
|
||||
/**
|
||||
* Returns the current item.
|
||||
*/
|
||||
current(): T;
|
||||
/**
|
||||
* Returns the next item.
|
||||
*/
|
||||
next(): T;
|
||||
/**
|
||||
* Returns the previous item.
|
||||
*/
|
||||
previous(): T;
|
||||
/**
|
||||
* Returns the item by going the given amount of `steps` through the array.
|
||||
* For example, calling `step(2)` is like calling `next()` twice. You go backward by specifying a negative number.
|
||||
* @param steps
|
||||
*/
|
||||
step(steps: number): T;
|
||||
/**
|
||||
* Returns an iterable that will cycle through the array indefinitely.
|
||||
*/
|
||||
indefinitely(): Iterator<T>;
|
||||
/**
|
||||
* Returns an iterable that will cycle through the array backward indefinitely.
|
||||
*/
|
||||
indefinitelyReversed(): Iterator<T>;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"cycled-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user