]>
Commit | Line | Data |
---|---|---|
4a6995be C |
1 | /* |
2 | * Custom Type Definitions | |
3 | * When including 3rd party modules you also need to include the type definition for the module | |
ab32b0fc | 4 | * if they don't provide one within the module. You can try to install it with @types |
4a6995be | 5 | |
ab32b0fc C |
6 | npm install @types/node |
7 | npm install @types/lodash | |
4a6995be | 8 | |
ab32b0fc | 9 | * If you can't find the type definition in the registry we can make an ambient/global definition in |
4a6995be C |
10 | * this file for now. For example |
11 | ||
ab32b0fc C |
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; | |
4a6995be C |
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; | |
ab32b0fc C |
32 | declare var _: any; |
33 | declare var $: any; | |
4a6995be C |
34 | |
35 | * | |
36 | * If you're importing a module that uses Node.js modules which are CommonJS you need to import as | |
ab32b0fc | 37 | * in the files such as main.browser.ts or any file within app/ |
4a6995be C |
38 | * |
39 | ||
40 | import * as _ from 'lodash' | |
41 | ||
ab32b0fc | 42 | * You can include your type definitions in this file until you create one for the @types |
4a6995be C |
43 | * |
44 | */ | |
45 | ||
ab32b0fc C |
46 | // support NodeJS modules without type definitions |
47 | declare module '*'; | |
4a6995be | 48 | |
c16ce1de C |
49 | /* |
50 | // for legacy tslint etc to understand rename 'modern-lru' with your package | |
51 | // then comment out `declare module '*';`. For each new module copy/paste | |
52 | // this method of creating an `any` module type definition | |
53 | declare module 'modern-lru' { | |
54 | let x: any; | |
55 | export = x; | |
56 | } | |
57 | */ | |
58 | ||
4a6995be C |
59 | // Extra variables that live on Global that will be replaced by webpack DefinePlugin |
60 | declare var ENV: string; | |
1840c2f7 | 61 | declare var API_URL: string; |
4a6995be | 62 | declare var HMR: boolean; |
ab32b0fc C |
63 | declare var System: SystemJS; |
64 | ||
65 | interface SystemJS { | |
66 | import: (path?: string) => Promise<any>; | |
67 | } | |
68 | ||
4a6995be | 69 | interface GlobalEnvironment { |
c16ce1de | 70 | ENV: string; |
1840c2f7 | 71 | API_URL: string; |
c16ce1de | 72 | HMR: boolean; |
ab32b0fc C |
73 | SystemJS: SystemJS; |
74 | System: SystemJS; | |
4a6995be C |
75 | } |
76 | ||
ab32b0fc C |
77 | interface Es6PromiseLoader { |
78 | (id: string): (exportName?: string) => Promise<any>; | |
79 | } | |
80 | ||
81 | type FactoryEs6PromiseLoader = () => Es6PromiseLoader; | |
82 | type FactoryPromise = () => Promise<any>; | |
83 | ||
84 | type AsyncRoutes = { | |
85 | [component: string]: Es6PromiseLoader | | |
86 | Function | | |
87 | FactoryEs6PromiseLoader | | |
8635a2c7 | 88 | FactoryPromise ; |
ab32b0fc C |
89 | }; |
90 | ||
ab32b0fc C |
91 | type IdleCallbacks = Es6PromiseLoader | |
92 | Function | | |
93 | FactoryEs6PromiseLoader | | |
94 | FactoryPromise ; | |
95 | ||
4a6995be C |
96 | interface WebpackModule { |
97 | hot: { | |
98 | data?: any, | |
99 | idle: any, | |
100 | accept(dependencies?: string | string[], callback?: (updatedDependencies?: any) => void): void; | |
ab32b0fc | 101 | decline(deps?: any | string | string[]): void; |
4a6995be C |
102 | dispose(callback?: (data?: any) => void): void; |
103 | addDisposeHandler(callback?: (data?: any) => void): void; | |
104 | removeDisposeHandler(callback?: (data?: any) => void): void; | |
105 | check(autoApply?: any, callback?: (err?: Error, outdatedModules?: any[]) => void): void; | |
106 | apply(options?: any, callback?: (err?: Error, outdatedModules?: any[]) => void): void; | |
107 | status(callback?: (status?: string) => void): void | string; | |
108 | removeStatusHandler(callback?: (status?: string) => void): void; | |
109 | }; | |
110 | } | |
111 | ||
112 | interface WebpackRequire { | |
ab32b0fc C |
113 | (id: string): any; |
114 | (paths: string[], callback: (...modules: any[]) => void): void; | |
115 | ensure(ids: string[], callback: (req: WebpackRequire) => void, chunkName?: string): void; | |
116 | context(directory: string, useSubDirectories?: boolean, regExp?: RegExp): WebpackContext; | |
4a6995be C |
117 | } |
118 | ||
ab32b0fc C |
119 | interface WebpackContext extends WebpackRequire { |
120 | keys(): string[]; | |
121 | } | |
4a6995be C |
122 | |
123 | interface ErrorStackTraceLimit { | |
124 | stackTraceLimit: number; | |
125 | } | |
126 | ||
4a6995be C |
127 | // Extend typings |
128 | interface NodeRequire extends WebpackRequire {} | |
129 | interface ErrorConstructor extends ErrorStackTraceLimit {} | |
ab32b0fc | 130 | interface NodeRequireFunction extends Es6PromiseLoader {} |
4a6995be C |
131 | interface NodeModule extends WebpackModule {} |
132 | interface Global extends GlobalEnvironment {} |