Use namespace to add tokenCache as prop of default export function

This commit is contained in:
Michael Dodge
2018-04-23 12:59:39 -06:00
parent 27e6fddf22
commit 3ec28e76de
2 changed files with 9 additions and 7 deletions
@@ -1,4 +1,4 @@
import tokenProvider, { tokenCache } from 'axios-token-interceptor';
import tokenProvider from 'axios-token-interceptor';
tokenProvider(); // $ExpectError
@@ -13,6 +13,6 @@ const getToken = Promise.resolve('qwerty');
const validCacheOptions = {
maxAge: 3600,
};
const cache = tokenCache(getToken, validCacheOptions); // $Expect TokenCache
const cache = tokenProvider.tokenCache(getToken, validCacheOptions); // $Expect TokenCache
cache.reset(); // $ExpectType void
+7 -5
View File
@@ -5,13 +5,15 @@
import { AxiosRequestConfig } from 'axios';
/*~ If this module has methods, declare them as functions like so.
*/
// Module
export function AxiosTokenProvider(Options: InterceptorOptions): TokenProvider;
export namespace AxiosTokenProvider {
function tokenCache(getToken: Promise<string>, options: TokenCacheOptions): TokenCache;
}
export default AxiosTokenProvider;
export default function tokenProvider(Options: InterceptorOptions): TokenProvider;
export function tokenCache(getToken: Promise<string>, options: TokenCacheOptions): TokenCache;
// Interfaces
/*~ You can declare types that are available via importing the module */
export interface InterceptorOptions {
token?: string;
getToken?: () => string | Promise<string>;