From e943205cf93f0a7a77616215223c79872298cd7f Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Sun, 20 May 2018 13:16:02 +0200 Subject: [PATCH 1/4] Add definitons for loadjs --- types/loadjs/index.d.ts | 38 +++++++++++++++++++++++++++ types/loadjs/test/loadjs-tests.ts | 23 ++++++++++++++++ types/loadjs/test/loadjs-umd-tests.ts | 17 ++++++++++++ types/loadjs/tsconfig.json | 24 +++++++++++++++++ types/loadjs/tslint.json | 1 + 5 files changed, 103 insertions(+) create mode 100644 types/loadjs/index.d.ts create mode 100644 types/loadjs/test/loadjs-tests.ts create mode 100644 types/loadjs/test/loadjs-umd-tests.ts create mode 100644 types/loadjs/tsconfig.json create mode 100644 types/loadjs/tslint.json diff --git a/types/loadjs/index.d.ts b/types/loadjs/index.d.ts new file mode 100644 index 0000000000..c8e3fc0d80 --- /dev/null +++ b/types/loadjs/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for loadjs 3.5 +// Project: https://github.com/muicss/loadjs +// Definitions by: Christian Rackerseder +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace loadjs; + +export = loadjs; + +declare function loadjs(file: string, loaded: loadjs.LoadedFn): void; +declare function loadjs(files: string[], loaded: loadjs.LoadedFn): void; +declare function loadjs(files: string[], bundleId: string): void; +declare function loadjs(files: string[], bundleId: string, loaded: loadjs.LoadedFn): void; +declare function loadjs(files: string[], bundleId: string, options: loadjs.LoadOptions): void; + +declare namespace loadjs { + export type LoadedFn = () => void; + + export interface LoadOptions { + before?(path: string, scriptEl: string): void; + success?(): void; + error?(depsNotFound: string): void; + async?: boolean; + numRetries?: number; + } + + export interface ReadyOptions { + success?(): void; + error?(depsNotFound: string): void; + } + + export function ready(bundleId: string, callback: LoadedFn): void; + export function ready(bundleIds: string[], callback: LoadedFn): void; + export function ready(bundleId: string, options: ReadyOptions): void; + export function isDefined(bundleId: string): boolean; + export function done(bundleId: string): void; + export function reset(): void; +} diff --git a/types/loadjs/test/loadjs-tests.ts b/types/loadjs/test/loadjs-tests.ts new file mode 100644 index 0000000000..0168130361 --- /dev/null +++ b/types/loadjs/test/loadjs-tests.ts @@ -0,0 +1,23 @@ +import * as importedLoadJs from 'loadjs'; + +const loadOptions: importedLoadJs.LoadOptions = { + before: (path, scriptEl) => {}, + success: () => {}, + error: (pathsNotFound) => {}, + async: true, + numRetries: 3 +}; + +const readyOptions: importedLoadJs.ReadyOptions = { + success: () => {}, + error: (depsNotFound) => {}, +}; + +importedLoadJs('/path/to/foo.js', () => {}); +importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], () => {}); +importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); +importedLoadJs.ready('foobar', () => {}); +importedLoadJs.ready(['foo', 'bar'], () => {}); +importedLoadJs.isDefined('foobar'); +importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', loadOptions); +importedLoadJs.ready('foobar', readyOptions); diff --git a/types/loadjs/test/loadjs-umd-tests.ts b/types/loadjs/test/loadjs-umd-tests.ts new file mode 100644 index 0000000000..1a35f04c43 --- /dev/null +++ b/types/loadjs/test/loadjs-umd-tests.ts @@ -0,0 +1,17 @@ +loadjs('/path/to/foo.js', () => {}); +loadjs(['/path/to/foo.js', '/path/to/bar.js'], () => {}); +loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); +loadjs.ready('foobar', () => {}); +loadjs.ready(['foo', 'bar'], () => {}); +loadjs.isDefined('foobar'); +loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { + before: (path, scriptEl) => {}, + success: () => {}, + error: (pathsNotFound) => {}, + async: true, + numRetries: 3 +}); +loadjs.ready('foobar', { + success: () => {}, + error: (depsNotFound) => {}, +}); diff --git a/types/loadjs/tsconfig.json b/types/loadjs/tsconfig.json new file mode 100644 index 0000000000..b60931cce6 --- /dev/null +++ b/types/loadjs/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "test/loadjs-tests.ts", + "test/loadjs-umd-tests.ts" + ] +} diff --git a/types/loadjs/tslint.json b/types/loadjs/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/loadjs/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 7ebaf74cde2ff2dc199ff8923676e55bf7b21fe8 Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Sun, 20 May 2018 17:00:56 +0200 Subject: [PATCH 2/4] Fix linting errors --- types/loadjs/index.d.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/types/loadjs/index.d.ts b/types/loadjs/index.d.ts index c8e3fc0d80..e68875e53a 100644 --- a/types/loadjs/index.d.ts +++ b/types/loadjs/index.d.ts @@ -2,21 +2,19 @@ // Project: https://github.com/muicss/loadjs // Definitions by: Christian Rackerseder // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 export as namespace loadjs; export = loadjs; -declare function loadjs(file: string, loaded: loadjs.LoadedFn): void; -declare function loadjs(files: string[], loaded: loadjs.LoadedFn): void; -declare function loadjs(files: string[], bundleId: string): void; -declare function loadjs(files: string[], bundleId: string, loaded: loadjs.LoadedFn): void; -declare function loadjs(files: string[], bundleId: string, options: loadjs.LoadOptions): void; +declare function loadjs(files: string | string[], bundleIdOrLoaded: string | loadjs.LoadedFn): void; +declare function loadjs(files: string[], bundleId: string, optionsOrCallback: loadjs.LoadOptions | loadjs.LoadedFn): void; declare namespace loadjs { - export type LoadedFn = () => void; + type LoadedFn = () => void; - export interface LoadOptions { + interface LoadOptions { before?(path: string, scriptEl: string): void; success?(): void; error?(depsNotFound: string): void; @@ -24,15 +22,13 @@ declare namespace loadjs { numRetries?: number; } - export interface ReadyOptions { + interface ReadyOptions { success?(): void; error?(depsNotFound: string): void; } - export function ready(bundleId: string, callback: LoadedFn): void; - export function ready(bundleIds: string[], callback: LoadedFn): void; - export function ready(bundleId: string, options: ReadyOptions): void; - export function isDefined(bundleId: string): boolean; - export function done(bundleId: string): void; - export function reset(): void; + function ready(bundleIds: string | string[], optionsOrCallback: ReadyOptions | LoadedFn): void; + function isDefined(bundleId: string): boolean; + function done(bundleId: string): void; + function reset(): void; } From 1b5b5ddfa1cb698e776be29034a80aaabc5fff6f Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Tue, 22 May 2018 07:06:11 +0200 Subject: [PATCH 3/4] Fixed import in test --- types/loadjs/test/loadjs-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/loadjs/test/loadjs-tests.ts b/types/loadjs/test/loadjs-tests.ts index 0168130361..e61df50ec8 100644 --- a/types/loadjs/test/loadjs-tests.ts +++ b/types/loadjs/test/loadjs-tests.ts @@ -1,4 +1,4 @@ -import * as importedLoadJs from 'loadjs'; +import importedLoadJs = require('loadjs'); const loadOptions: importedLoadJs.LoadOptions = { before: (path, scriptEl) => {}, From 1a20dc303b7a9f8180747e26f145d1ebad3bee93 Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Thu, 24 May 2018 07:46:15 +0200 Subject: [PATCH 4/4] Fix return type of ready() function --- types/loadjs/index.d.ts | 2 +- types/loadjs/test/loadjs-tests.ts | 4 ++-- types/loadjs/test/loadjs-umd-tests.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/loadjs/index.d.ts b/types/loadjs/index.d.ts index e68875e53a..9373308815 100644 --- a/types/loadjs/index.d.ts +++ b/types/loadjs/index.d.ts @@ -27,7 +27,7 @@ declare namespace loadjs { error?(depsNotFound: string): void; } - function ready(bundleIds: string | string[], optionsOrCallback: ReadyOptions | LoadedFn): void; + function ready(bundleIds: string | string[], optionsOrCallback: ReadyOptions | LoadedFn): typeof loadjs; function isDefined(bundleId: string): boolean; function done(bundleId: string): void; function reset(): void; diff --git a/types/loadjs/test/loadjs-tests.ts b/types/loadjs/test/loadjs-tests.ts index e61df50ec8..0b3aad142d 100644 --- a/types/loadjs/test/loadjs-tests.ts +++ b/types/loadjs/test/loadjs-tests.ts @@ -16,8 +16,8 @@ const readyOptions: importedLoadJs.ReadyOptions = { importedLoadJs('/path/to/foo.js', () => {}); importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], () => {}); importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); -importedLoadJs.ready('foobar', () => {}); -importedLoadJs.ready(['foo', 'bar'], () => {}); +importedLoadJs.ready('foobar', () => {}).ready('foobar', () => {}); +importedLoadJs.ready(['foo', 'bar'], () => {}).ready(['foo', 'bar'], () => {}); importedLoadJs.isDefined('foobar'); importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', loadOptions); importedLoadJs.ready('foobar', readyOptions); diff --git a/types/loadjs/test/loadjs-umd-tests.ts b/types/loadjs/test/loadjs-umd-tests.ts index 1a35f04c43..94ee4f5090 100644 --- a/types/loadjs/test/loadjs-umd-tests.ts +++ b/types/loadjs/test/loadjs-umd-tests.ts @@ -1,8 +1,8 @@ loadjs('/path/to/foo.js', () => {}); loadjs(['/path/to/foo.js', '/path/to/bar.js'], () => {}); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); -loadjs.ready('foobar', () => {}); -loadjs.ready(['foo', 'bar'], () => {}); +loadjs.ready('foobar', () => {}).ready('foobar', () => {}); +loadjs.ready(['foo', 'bar'], () => {}).ready(['foo', 'bar'], () => {}); loadjs.isDefined('foobar'); loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { before: (path, scriptEl) => {},