Merge pull request #25895 from screendriver/loadjs

Add definitons for loadjs
This commit is contained in:
Daniel Rosenwasser
2018-05-23 22:53:54 -07:00
committed by GitHub
5 changed files with 99 additions and 0 deletions

34
types/loadjs/index.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
// Type definitions for loadjs 3.5
// Project: https://github.com/muicss/loadjs
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
// 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;
}

View File

@@ -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);

View File

@@ -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) => {},
});

View File

@@ -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"
]
}

1
types/loadjs/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }