4 * Custom Type Definitions
5 * When including 3rd party modules you also need to include the type definition for the module
6 * if they don't provide one within the module. You can try to install it with @types
8 npm install @types/node
9 npm install @types/lodash
11 * If you can't find the type definition in the registry we can make an ambient/global definition in
12 * this file for now. For example
14 declare module 'my-module' {
15 export function doesSomething(value: string): string;
18 * If you are using a CommonJS module that is using module.exports then you will have to write your
19 * types using export = yourObjectOrFunction with a namespace above it
20 * notice how we have to create a namespace that is equal to the function we're
21 * assigning the export to
23 declare module 'jwt-decode' {
24 function jwtDecode(token: string): any;
25 namespace jwtDecode {}
30 * If you're prototying and you will fix the types later you can also declare it as type any
33 declare var assert: any;
38 * If you're importing a module that uses Node.js modules which are CommonJS you need to import as
39 * in the files such as main.browser.ts or any file within app/
42 import * as _ from 'lodash'
44 * You can include your type definitions in this file until you create one for the @types
48 // support NodeJS modules without type definitions
52 // for legacy tslint etc to understand rename 'modern-lru' with your package
53 // then comment out `declare module '*';`. For each new module copy/paste
54 // this method of creating an `any` module type definition
55 declare module 'modern-lru' {
61 // Extra variables that live on Global that will be replaced by webpack DefinePlugin
62 declare var ENV: string;
63 declare var API_URL: string;
64 declare var HMR: boolean;
65 declare var System: SystemJS;
68 import: (path?: string) => Promise<any>;
71 interface GlobalEnvironment {
79 interface Es6PromiseLoader {
80 (id: string): (exportName?: string) => Promise<any>;
83 type FactoryEs6PromiseLoader = () => Es6PromiseLoader;
84 type FactoryPromise = () => Promise<any>;
87 [component: string]: Es6PromiseLoader |
89 FactoryEs6PromiseLoader |
93 type IdleCallbacks = Es6PromiseLoader |
95 FactoryEs6PromiseLoader |
98 interface WebpackModule {
102 accept(dependencies?: string | string[], callback?: (updatedDependencies?: any) => void): void;
103 decline(deps?: any | string | string[]): void;
104 dispose(callback?: (data?: any) => void): void;
105 addDisposeHandler(callback?: (data?: any) => void): void;
106 removeDisposeHandler(callback?: (data?: any) => void): void;
107 check(autoApply?: any, callback?: (err?: Error, outdatedModules?: any[]) => void): void;
108 apply(options?: any, callback?: (err?: Error, outdatedModules?: any[]) => void): void;
109 status(callback?: (status?: string) => void): void | string;
110 removeStatusHandler(callback?: (status?: string) => void): void;
114 interface WebpackRequire {
116 (paths: string[], callback: (...modules: any[]) => void): void;
117 ensure(ids: string[], callback: (req: WebpackRequire) => void, chunkName?: string): void;
118 context(directory: string, useSubDirectories?: boolean, regExp?: RegExp): WebpackContext;
121 interface WebpackContext extends WebpackRequire {
125 interface ErrorStackTraceLimit {
126 stackTraceLimit: number;
130 interface NodeRequire extends WebpackRequire {}
131 interface ErrorConstructor extends ErrorStackTraceLimit {}
132 interface NodeRequireFunction extends Es6PromiseLoader {}
133 interface NodeModule extends WebpackModule {}
134 interface Global extends GlobalEnvironment {}