]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Custom Type Definitions | |
3 | * When including 3rd party modules you also need to include the type definition for the module | |
4 | * if they don't provide one within the module. You can try to install it with @types | |
5 | ||
6 | npm install @types/node | |
7 | npm install @types/lodash | |
8 | ||
9 | * If you can't find the type definition in the registry we can make an ambient/global definition in | |
10 | * this file for now. For example | |
11 | ||
12 | declare module 'my-module' { | |
13 | export function doesSomething(value: string): string; | |
14 | } | |
15 | ||
16 | * If you are using a CommonJS module that is using module.exports then you will have to write your | |
17 | * types using export = yourObjectOrFunction with a namespace above it | |
18 | * notice how we have to create a namespace that is equal to the function we're | |
19 | * assigning the export to | |
20 | ||
21 | declare module 'jwt-decode' { | |
22 | function jwtDecode(token: string): any; | |
23 | namespace jwtDecode {} | |
24 | export = jwtDecode; | |
25 | } | |
26 | ||
27 | * | |
28 | * If you're prototying and you will fix the types later you can also declare it as type any | |
29 | * | |
30 | ||
31 | declare var assert: any; | |
32 | declare var _: any; | |
33 | declare var $: any; | |
34 | ||
35 | * | |
36 | * If you're importing a module that uses Node.js modules which are CommonJS you need to import as | |
37 | * in the files such as main.browser.ts or any file within app/ | |
38 | * | |
39 | ||
40 | import * as _ from 'lodash' | |
41 | ||
42 | * You can include your type definitions in this file until you create one for the @types | |
43 | * | |
44 | */ | |
45 | ||
46 | // support NodeJS modules without type definitions | |
47 | declare module '*'; | |
48 | ||
49 | // Extra variables that live on Global that will be replaced by webpack DefinePlugin | |
50 | declare var ENV: string; | |
51 | declare var HMR: boolean; | |
52 | declare var System: SystemJS; | |
53 | ||
54 | interface SystemJS { | |
55 | import: (path?: string) => Promise<any>; | |
56 | } | |
57 | ||
58 | interface GlobalEnvironment { | |
59 | ENV; | |
60 | HMR; | |
61 | SystemJS: SystemJS; | |
62 | System: SystemJS; | |
63 | } | |
64 | ||
65 | interface Es6PromiseLoader { | |
66 | (id: string): (exportName?: string) => Promise<any>; | |
67 | } | |
68 | ||
69 | type FactoryEs6PromiseLoader = () => Es6PromiseLoader; | |
70 | type FactoryPromise = () => Promise<any>; | |
71 | ||
72 | type AsyncRoutes = { | |
73 | [component: string]: Es6PromiseLoader | | |
74 | Function | | |
75 | FactoryEs6PromiseLoader | | |
76 | FactoryPromise | |
77 | }; | |
78 | ||
79 | ||
80 | type IdleCallbacks = Es6PromiseLoader | | |
81 | Function | | |
82 | FactoryEs6PromiseLoader | | |
83 | FactoryPromise ; | |
84 | ||
85 | interface WebpackModule { | |
86 | hot: { | |
87 | data?: any, | |
88 | idle: any, | |
89 | accept(dependencies?: string | string[], callback?: (updatedDependencies?: any) => void): void; | |
90 | decline(deps?: any | string | string[]): void; | |
91 | dispose(callback?: (data?: any) => void): void; | |
92 | addDisposeHandler(callback?: (data?: any) => void): void; | |
93 | removeDisposeHandler(callback?: (data?: any) => void): void; | |
94 | check(autoApply?: any, callback?: (err?: Error, outdatedModules?: any[]) => void): void; | |
95 | apply(options?: any, callback?: (err?: Error, outdatedModules?: any[]) => void): void; | |
96 | status(callback?: (status?: string) => void): void | string; | |
97 | removeStatusHandler(callback?: (status?: string) => void): void; | |
98 | }; | |
99 | } | |
100 | ||
101 | ||
102 | interface WebpackRequire { | |
103 | (id: string): any; | |
104 | (paths: string[], callback: (...modules: any[]) => void): void; | |
105 | ensure(ids: string[], callback: (req: WebpackRequire) => void, chunkName?: string): void; | |
106 | context(directory: string, useSubDirectories?: boolean, regExp?: RegExp): WebpackContext; | |
107 | } | |
108 | ||
109 | interface WebpackContext extends WebpackRequire { | |
110 | keys(): string[]; | |
111 | } | |
112 | ||
113 | interface ErrorStackTraceLimit { | |
114 | stackTraceLimit: number; | |
115 | } | |
116 | ||
117 | ||
118 | // Extend typings | |
119 | interface NodeRequire extends WebpackRequire {} | |
120 | interface ErrorConstructor extends ErrorStackTraceLimit {} | |
121 | interface NodeRequireFunction extends Es6PromiseLoader {} | |
122 | interface NodeModule extends WebpackModule {} | |
123 | interface Global extends GlobalEnvironment {} |