mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[loadjs] v4 definitions (#38941)
This commit is contained in:
parent
b8a7daa927
commit
ca5aab8759
38
types/loadjs/index.d.ts
vendored
38
types/loadjs/index.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
// Type definitions for loadjs 3.5
|
||||
// Type definitions for loadjs 4.0
|
||||
// Project: https://github.com/muicss/loadjs
|
||||
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
|
||||
// Aziz Khambati <https://github.com/azizhk>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
@ -8,23 +9,46 @@ 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 function loadjs(
|
||||
files: string | string[],
|
||||
bundleIdOrLoaded: string | loadjs.LoadOptions | loadjs.LoadedFn,
|
||||
): void;
|
||||
|
||||
declare function loadjs(
|
||||
files: string | string[],
|
||||
bundleId: string,
|
||||
optionsOrCallback: loadjs.LoadOptions | loadjs.LoadedFn
|
||||
): void;
|
||||
|
||||
declare function loadjs(
|
||||
files: string | string[],
|
||||
options: loadjs.LoadOptions & {
|
||||
returnPromise: true
|
||||
}
|
||||
): Promise<void>;
|
||||
|
||||
declare function loadjs(
|
||||
files: string | string[],
|
||||
bundleId: string,
|
||||
options: loadjs.LoadOptions & {
|
||||
returnPromise: true
|
||||
}
|
||||
): Promise<void>;
|
||||
|
||||
declare namespace loadjs {
|
||||
type LoadedFn = () => void;
|
||||
|
||||
interface LoadOptions {
|
||||
before?(path: string, scriptEl: string): void;
|
||||
success?(): void;
|
||||
error?(depsNotFound: string): void;
|
||||
before?(path: string, scriptEl: HTMLElement): void;
|
||||
async?: boolean;
|
||||
numRetries?: number;
|
||||
success?(): void; // Arguments provided are different in case of returnPromise: true / false
|
||||
error?(depsNotFound: string[]): void;
|
||||
}
|
||||
|
||||
interface ReadyOptions {
|
||||
success?(): void;
|
||||
error?(depsNotFound: string): void;
|
||||
error?(depsNotFound: string[]): void;
|
||||
}
|
||||
|
||||
function ready(bundleIds: string | string[], optionsOrCallback: ReadyOptions | LoadedFn): typeof loadjs;
|
||||
|
||||
@ -1,23 +1,35 @@
|
||||
import importedLoadJs = require('loadjs');
|
||||
|
||||
const loadOptions: importedLoadJs.LoadOptions = {
|
||||
before: (path, scriptEl) => {},
|
||||
before: (path, scriptEl) => {
|
||||
path; // $ExpectType string
|
||||
scriptEl; // $ExpectType HTMLElement
|
||||
},
|
||||
success: () => {},
|
||||
error: (pathsNotFound) => {},
|
||||
error: (pathsNotFound) => {
|
||||
pathsNotFound; // $ExpectType string[]
|
||||
},
|
||||
async: true,
|
||||
numRetries: 3
|
||||
};
|
||||
|
||||
const readyOptions: importedLoadJs.ReadyOptions = {
|
||||
success: () => {},
|
||||
error: (depsNotFound) => {},
|
||||
error: (depsNotFound) => {
|
||||
depsNotFound; // $ExpectType string[]
|
||||
},
|
||||
};
|
||||
|
||||
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);
|
||||
importedLoadJs('/path/to/foo.js', () => {}); // $ExpectType void
|
||||
importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], () => {}); // $ExpectType void
|
||||
importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar'); // $ExpectType void
|
||||
importedLoadJs.ready('foobar', () => {}).ready('foobar', () => {}); // $ExpectType typeof loadjs
|
||||
importedLoadJs.ready(['foo', 'bar'], () => {}).ready(['foo', 'bar'], () => {}); // $ExpectType typeof loadjs
|
||||
importedLoadJs.isDefined('foobar'); // $ExpectType boolean
|
||||
importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', loadOptions); // $ExpectType void
|
||||
importedLoadJs.ready('foobar', readyOptions); // $ExpectType typeof loadjs
|
||||
|
||||
importedLoadJs('/path/to/foo.js', { ...loadOptions, returnPromise: true }); // $ExpectType Promise<void>
|
||||
importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], { ...loadOptions, returnPromise: true }); // $ExpectType Promise<void>
|
||||
importedLoadJs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { ...loadOptions, returnPromise: true }); // $ExpectType Promise<void>
|
||||
importedLoadJs('/path/to/foo.js', 'foo', { ...loadOptions, returnPromise: true }); // $ExpectType Promise<void>
|
||||
|
||||
@ -15,3 +15,8 @@ loadjs.ready('foobar', {
|
||||
success: () => {},
|
||||
error: (depsNotFound) => {},
|
||||
});
|
||||
|
||||
loadjs('/path/to/foo.js', { returnPromise: true }).then(() => {});
|
||||
loadjs('/path/to/foo.js', 'foobar', { returnPromise: true }).then(() => {});
|
||||
loadjs(['/path/to/foo.js', '/path/to/bar.js'], { returnPromise: true }).then(() => {});
|
||||
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', { returnPromise: true }).then(() => {});
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user