diff --git a/types/loadjs/index.d.ts b/types/loadjs/index.d.ts new file mode 100644 index 0000000000..9373308815 --- /dev/null +++ b/types/loadjs/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for loadjs 3.5 +// 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(files: string | string[], bundleIdOrLoaded: string | loadjs.LoadedFn): void; +declare function loadjs(files: string[], bundleId: string, optionsOrCallback: loadjs.LoadOptions | loadjs.LoadedFn): void; + +declare namespace loadjs { + type LoadedFn = () => void; + + interface LoadOptions { + before?(path: string, scriptEl: string): void; + success?(): void; + error?(depsNotFound: string): void; + async?: boolean; + numRetries?: number; + } + + interface ReadyOptions { + success?(): void; + error?(depsNotFound: string): 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 new file mode 100644 index 0000000000..0b3aad142d --- /dev/null +++ b/types/loadjs/test/loadjs-tests.ts @@ -0,0 +1,23 @@ +import importedLoadJs = require('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', () => {}).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 new file mode 100644 index 0000000000..94ee4f5090 --- /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', () => {}).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) => {}, + 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" }