From f316905e97948233051cbc4d4a76b9cffe0cceee Mon Sep 17 00:00:00 2001 From: KevinRamharak Date: Mon, 21 May 2018 10:52:33 +0200 Subject: [PATCH 1/2] added type definitions for NPM package module-alias --- types/module-alias/index.d.ts | 44 ++++++++++++++++++++++++ types/module-alias/module-alias-tests.ts | 3 ++ types/module-alias/tsconfig.json | 23 +++++++++++++ types/module-alias/tslint.json | 1 + 4 files changed, 71 insertions(+) create mode 100644 types/module-alias/index.d.ts create mode 100644 types/module-alias/module-alias-tests.ts create mode 100644 types/module-alias/tsconfig.json create mode 100644 types/module-alias/tslint.json diff --git a/types/module-alias/index.d.ts b/types/module-alias/index.d.ts new file mode 100644 index 0000000000..159b78111b --- /dev/null +++ b/types/module-alias/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for module-alias 2.0 +// Project: https://github.com/ilearnio/module-alias/ +// Definitions by: Kevin Ramharak +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/ + +export = init; + +/** + * Import aliases from package.json + */ +declare function init(options?: string | init.Options): void; + +declare namespace init { + function isPathMatchesAlias(path: string, alias: string): boolean; + + /** + * Register a custom modules directory + */ + function addPath(path: string): void; + + /** + * Register a single alias + */ + function addAlias(alias: string, path: string): void; + + /** + * Register mutliple aliases + */ + function addAliases(aliases: { [alias: string]: string }): void; + + /** + * Reset any changes maded (resets all registered aliases + * and custom module directories) + * The function is undocumented and for testing purposes only + */ + function reset(): void; + + /** + * module intialis options type + */ + interface Options { + base: string; + } +} diff --git a/types/module-alias/module-alias-tests.ts b/types/module-alias/module-alias-tests.ts new file mode 100644 index 0000000000..06f56f3ac2 --- /dev/null +++ b/types/module-alias/module-alias-tests.ts @@ -0,0 +1,3 @@ +import * as moduleAlias from 'module-alias'; + +moduleAlias.isPathMatchesAlias('./path', '@alias'); // $ExpectType boolean diff --git a/types/module-alias/tsconfig.json b/types/module-alias/tsconfig.json new file mode 100644 index 0000000000..b9063a644a --- /dev/null +++ b/types/module-alias/tsconfig.json @@ -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", + "module-alias-tests.ts" + ] +} diff --git a/types/module-alias/tslint.json b/types/module-alias/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/module-alias/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 6891a455e9b34b7668ed1429604cad59fe485c0b Mon Sep 17 00:00:00 2001 From: KevinRamharak Date: Tue, 22 May 2018 11:34:47 +0200 Subject: [PATCH 2/2] changed import statement and added tests --- types/module-alias/index.d.ts | 3 +++ types/module-alias/module-alias-tests.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/types/module-alias/index.d.ts b/types/module-alias/index.d.ts index 159b78111b..09fd2f7ed8 100644 --- a/types/module-alias/index.d.ts +++ b/types/module-alias/index.d.ts @@ -10,6 +10,9 @@ export = init; */ declare function init(options?: string | init.Options): void; +/** + * Exported functoins + */ declare namespace init { function isPathMatchesAlias(path: string, alias: string): boolean; diff --git a/types/module-alias/module-alias-tests.ts b/types/module-alias/module-alias-tests.ts index 06f56f3ac2..6e5ddfc7ee 100644 --- a/types/module-alias/module-alias-tests.ts +++ b/types/module-alias/module-alias-tests.ts @@ -1,3 +1,12 @@ -import * as moduleAlias from 'module-alias'; +import moduleAlias = require('module-alias'); + +moduleAlias('path'); // $ExpectType void +moduleAlias({ base : 'path' }); // $ExpectType void moduleAlias.isPathMatchesAlias('./path', '@alias'); // $ExpectType boolean + +moduleAlias.addPath('path'); // $ExpectType void +moduleAlias.addAliases({ alias : 'path', anotherAlias : 'anotherPath' }); // $ExpectType void +moduleAlias.addAlias('@alias', 'somePath'); // $ExpectType void + +moduleAlias.reset(); // $ExpectType void