mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Types for undertaker-registry@1.0 (#16146)
* undertaker-registry initial commit. * Created index.d.ts for undertaker-registry * Created tslint.json for undertaker-registry * Created tests for undertaker-registry.
This commit is contained in:
parent
d286c0ac79
commit
94f553150d
43
types/undertaker-registry/index.d.ts
vendored
Normal file
43
types/undertaker-registry/index.d.ts
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// Type definitions for undertaker-registry 1.0
|
||||
// Project: https://github.com/gulpjs/undertaker-registry
|
||||
// Definitions by: Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class UndertakerRegistry {
|
||||
/**
|
||||
* Returns the task with that name or undefined if no task is registered with that name.
|
||||
* Useful for custom task storage.
|
||||
* Custom registries can override this method when inheriting from this default registry.
|
||||
* @param taskName {string} - Name of task.
|
||||
*/
|
||||
get<TTaskFunction>(taskName: string): TTaskFunction;
|
||||
|
||||
/**
|
||||
* No-op method that receives the undertaker instance.
|
||||
* Useful to set pre-defined tasks using the undertaker.task(taskName, fn) method.
|
||||
* Custom registries can override this method when inheriting from this default registry.
|
||||
* @param taker {any} - Instance of undertaker.
|
||||
*/
|
||||
init(taker: any): void;
|
||||
|
||||
/**
|
||||
* Adds a task to the registry.
|
||||
* If set modifies a task, it should return the new task so Undertaker can properly maintain metadata for the task.
|
||||
* Useful for adding custom behavior to every task as it is registered in the system.
|
||||
* Custom registries can override this method when inheriting from this default registry.
|
||||
* @param taskName {string} - Name of task.
|
||||
* @param fn {UndertakerRegistry.TaskFunction} - Task function.
|
||||
*/
|
||||
set<TTaskFunction>(taskName: string, fn: TTaskFunction): TTaskFunction;
|
||||
|
||||
/**
|
||||
* Returns an object listing all tasks in the registry.
|
||||
* Necessary to override if the get method is overridden for custom task storage.
|
||||
* Custom registries can override this when when inheriting from this default registry.
|
||||
*/
|
||||
tasks(): { [taskName: string]: (...args: any[]) => any };
|
||||
}
|
||||
|
||||
declare namespace UndertakerRegistry { }
|
||||
|
||||
export = UndertakerRegistry;
|
||||
22
types/undertaker-registry/tsconfig.json
Normal file
22
types/undertaker-registry/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"undertaker-registry-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/undertaker-registry/tslint.json
Normal file
1
types/undertaker-registry/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
37
types/undertaker-registry/undertaker-registry-tests.ts
Normal file
37
types/undertaker-registry/undertaker-registry-tests.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import * as UndertakerRegistry from "undertaker-registry";
|
||||
|
||||
const ArgTask = (firstArg: string, secondArg: number) => {
|
||||
// Task
|
||||
};
|
||||
|
||||
const NoArgTask = () => {
|
||||
// Task without arguments
|
||||
};
|
||||
|
||||
const registryInstance = new UndertakerRegistry();
|
||||
|
||||
const setTask = registryInstance.set("task", ArgTask);
|
||||
setTask("string", 123);
|
||||
|
||||
const getTask = registryInstance.get<typeof ArgTask>("taskName");
|
||||
getTask("string", 123);
|
||||
|
||||
const tasks = registryInstance.tasks();
|
||||
const taskFromTasks = tasks["task"] as typeof ArgTask;
|
||||
taskFromTasks("string", 123);
|
||||
|
||||
class MyRegistry extends UndertakerRegistry { }
|
||||
|
||||
registryInstance.init(MyRegistry);
|
||||
|
||||
const myRegistryInstance = new MyRegistry();
|
||||
|
||||
const setTask2 = registryInstance.set("task", NoArgTask);
|
||||
setTask2();
|
||||
|
||||
const getTask2 = registryInstance.get<typeof NoArgTask>("taskName");
|
||||
getTask2();
|
||||
|
||||
const tasks2 = registryInstance.tasks();
|
||||
const taskFromTasks2 = tasks["task"] as typeof NoArgTask;
|
||||
taskFromTasks2();
|
||||
Loading…
Reference in New Issue
Block a user