diff --git a/types/systemjs/index.d.ts b/types/systemjs/index.d.ts index 8f230e7c09..7b659ca747 100644 --- a/types/systemjs/index.d.ts +++ b/types/systemjs/index.d.ts @@ -1,11 +1,28 @@ // Type definitions for SystemJS 0.20 // Project: https://github.com/systemjs/systemjs -// Definitions by: Ludovic HENIN , Nathan Walker , Giedrius Grabauskas +// Definitions by: Ludovic HENIN +// Nathan Walker +// Giedrius Grabauskas +// Aluan Haddad // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +export = SystemJSLoader; + +export as namespace SystemJSLoader; + +declare global { + const SystemJS: typeof SystemJSLoader; + + /** + * @deprecated use SystemJS https://github.com/systemjs/systemjs/releases/tag/0.19.10 + */ + const System: typeof SystemJSLoader; + const __moduleName: string; +} + +declare const SystemJSLoader: SystemJSLoader.System; declare namespace SystemJSLoader { - interface ModulesList { [bundleName: string]: string[]; } @@ -173,7 +190,7 @@ declare namespace SystemJSLoader { /** * Set the Babel transpiler options when System.transpiler is set to babel. */ - //TODO: Import BabelCore.TransformOptions + // TODO: Import BabelCore.TransformOptions babelOptions?: any; /** @@ -234,7 +251,7 @@ declare namespace SystemJSLoader { /** * Sets the TypeScript transpiler options. */ - //TODO: Import Typescript.CompilerOptions + // TODO: Import Typescript.CompilerOptions typescriptOptions?: { /** * A boolean flag which instructs the plugin to load configuration from "tsconfig.json". @@ -248,25 +265,16 @@ declare namespace SystemJSLoader { }; } - interface SystemJSSystemFields { - env: string; - loaderErrorStack: boolean; - packageConfigPaths: string[]; - pluginFirst: boolean; - version: string; - warnings: boolean; - } - - interface System extends Config, SystemJSSystemFields { + interface System extends Config { /** * For backwards-compatibility with AMD environments, set window.define = System.amdDefine. */ - amdDefine: (...args: any[]) => void; + amdDefine(...args: any[]): void; /** * For backwards-compatibility with AMD environments, set window.require = System.amdRequire. */ - amdRequire: (deps: string[], callback: (...modules: any[]) => void) => void; + amdRequire(deps: string[], callback: (...modules: any[]) => void): void; /** * SystemJS configuration helper function. @@ -288,7 +296,6 @@ declare namespace SystemJSLoader { * Returns a module from the registry by normalized name. */ get(moduleName: string): any; - get(moduleName: string): TModule; /** * Returns a clone of the internal SystemJS configuration in use. @@ -305,7 +312,6 @@ declare namespace SystemJSLoader { * Promise resolves to the module value. */ import(moduleName: string, normalizedParentName?: string): Promise; - import(moduleName: string, normalizedParentName?: string): Promise; /** * Given any object, returns true if the object is either a SystemJS module or native JavaScript module object, and false otherwise. @@ -318,7 +324,6 @@ declare namespace SystemJSLoader { * Useful when writing a custom instantiate hook or using System.set. */ newModule(object: any): any; - newModule(object: any): TModule; /** * Declaration function for defining modules of the System.register polyfill module format. @@ -349,32 +354,35 @@ declare namespace SystemJSLoader { * Synchronous alternative to `SystemJS.resolve`. */ resolveSync(moduleName: string, parentName?: string): string; - + /** * In CommonJS environments, SystemJS will substitute the global require as needed by the module format being * loaded to ensure the correct detection paths in loaded code. * The CommonJS require can be recovered within these modules from System._nodeRequire. */ - _nodeRequire: (dep: string) => any; + _nodeRequire(dep: string): any; /** * Modules list available only with trace=true */ loads: PackageList; + + env: string; + + loaderErrorStack: boolean; + + packageConfigPaths: string[]; + + /** + * Specify a value of true to have SystemJS conform to the AMD-style plugin syntax, e.g. "text!some/file.txt", over the default of "some/file.txt!text". + */ + pluginFirst: boolean; + + version: string; + + /** + * Enables the output of warnings to the console, including deprecation messages. + */ + warnings: boolean; } } - -declare var SystemJS: SystemJSLoader.System; - -declare var __moduleName: string; - -/** - * @deprecated use SystemJS https://github.com/systemjs/systemjs/releases/tag/0.19.10 - */ -declare const System: SystemJSLoader.System; - -declare module "systemjs" { - import systemJSLoader = SystemJSLoader; - const system: systemJSLoader.System; - export = system; -} diff --git a/types/systemjs/systemjs-tests.ts b/types/systemjs/systemjs-tests.ts index eb663a1e2c..4161060421 100644 --- a/types/systemjs/systemjs-tests.ts +++ b/types/systemjs/systemjs-tests.ts @@ -7,15 +7,13 @@ SystemJS.config({ SystemJS.import('main.js'); SystemJS.config({ - // or 'traceur' or 'typescript' - transpiler: 'babel', - // or traceurOptions or typescriptOptions + // 'plugin-traceur' or 'plugin-typescript' or 'babel' or 'traceur' or 'typescript' or false. + transpiler: 'plugin-babel', + // or traceurOptions or typescriptOptions babelOptions: { - } }); - SystemJS.config({ map: { traceur: 'path/to/traceur.js' @@ -39,26 +37,32 @@ SystemJS.config({ }); SystemJS.config({ - map: { - 'local/package': { - x: 'vendor/x.js' - }, - 'another/package': { - x: 'vendor/y.js' + map: { + 'local/package': { + x: 'vendor/x.js' + }, + 'another/package': { + x: 'vendor/y.js' + } } - } }); SystemJS.transpiler = 'traceur'; +const mockModule = { + default: () => { + return 42; + } +}; -// loads './app.js' from the current directory -SystemJS.import('./app.js').then(function (m) { - console.log(m); +SystemJS.set('./app.js', SystemJS.newModule(mockModule)); + +SystemJS.import('./app.js').then((m: typeof mockModule) => { + m.default(); }); -SystemJS.import('lodash').then(function (_) { - console.log(_); +SystemJS.import('lodash').then((_: (...args: any[]) => any) => { + _(1, '2', {}, []); }); const clonedSystemJSJS = new SystemJS.constructor(); diff --git a/types/systemjs/tsconfig.json b/types/systemjs/tsconfig.json index 0bfbfa8a16..95bed64e3b 100644 --- a/types/systemjs/tsconfig.json +++ b/types/systemjs/tsconfig.json @@ -2,8 +2,7 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6", - "dom" + "es6" ], "noImplicitAny": true, "noImplicitThis": true, diff --git a/types/systemjs/tslint.json b/types/systemjs/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/systemjs/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}