mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Allow init to transform config
This commit is contained in:
+13
-6
@@ -91,12 +91,18 @@ interface KnownConfig {
|
||||
prop: string;
|
||||
}
|
||||
var knownConfig = interceptor({
|
||||
init: (config: KnownConfig) => {
|
||||
config.prop = config.prop || 'default-value';
|
||||
return config;
|
||||
},
|
||||
success: (response: rest.Response, config: KnownConfig) => {
|
||||
console.log(config.prop);
|
||||
console.log(config);
|
||||
return response;
|
||||
},
|
||||
});
|
||||
|
||||
var transformedConfig = interceptor({
|
||||
init: (config: KnownConfig) => {
|
||||
return config.prop;
|
||||
},
|
||||
success: (response: rest.Response, config: string) => {
|
||||
console.log(config);
|
||||
return response;
|
||||
},
|
||||
});
|
||||
@@ -127,4 +133,5 @@ client = rest
|
||||
.wrap(xhr)
|
||||
.wrap(noop)
|
||||
.wrap(fail)
|
||||
.wrap(knownConfig, { prop: 'value' });
|
||||
.wrap(knownConfig, { prop: 'value' })
|
||||
.wrap(transformedConfig, { prop: 'value' });
|
||||
|
||||
Vendored
+7
-7
@@ -71,15 +71,15 @@ declare module "rest/interceptor" {
|
||||
import when = require("when");
|
||||
import rest = require("rest");
|
||||
|
||||
function interceptor<T>(config: interceptor.Config<T>): rest.Interceptor<T>;
|
||||
function interceptor<T, U>(config: interceptor.Config<T, U>): rest.Interceptor<T>;
|
||||
|
||||
module interceptor {
|
||||
interface Config<T> {
|
||||
init?: (config: T) => T;
|
||||
request?: (request: rest.Request, config: T, meta: rest.Meta) => rest.Request | when.Promise<rest.Request>;
|
||||
response?: (response: rest.Response, config: T, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
|
||||
success?: (response: rest.Response, config: T, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
|
||||
error?: (response: rest.Response, config: T, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
|
||||
interface Config<T, U> {
|
||||
init?: (config: T) => U;
|
||||
request?: (request: rest.Request, config: U, meta: rest.Meta) => rest.Request | when.Promise<rest.Request>;
|
||||
response?: (response: rest.Response, config: U, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
|
||||
success?: (response: rest.Response, config: U, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
|
||||
error?: (response: rest.Response, config: U, meta: rest.Meta) => rest.Response | when.Promise<rest.Response>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user