Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#67409 Update axios-token-interceptor types…
Browse files Browse the repository at this point in the history
… - works with old and new versions by @mgdodge

* Update axios-token-interceptor types - works with old and new versions

* Fix typo in "owners" section of package.json

---------

Co-authored-by: Mike Dodge <[email protected]>
  • Loading branch information
mgdodge and Mike Dodge authored Nov 29, 2023
1 parent a8ef356 commit 2ec8a47
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from "axios";
import tokenProvider = require("axios-token-interceptor");

const getToken = async (): Promise<tokenProvider.Token> => ({
Expand All @@ -20,12 +21,14 @@ tokenProvider();
const validOptions1 = {
getToken: () => "qwerty",
};
tokenProvider(validOptions1); // $ExpectType TokenProvider
const provider1 = tokenProvider(validOptions1); // $ExpectType TokenProvider
axios.interceptors.request.use(provider1);

const validOptions2 = {
getToken: () => Promise.resolve("qwerty"),
};
tokenProvider(validOptions2); // $ExpectType TokenProvider
const provider2 = tokenProvider(validOptions2); // $ExpectType TokenProvider
axios.interceptors.request.use(provider2);

// @ts-expect-error
tokenProvider.tokenCache();
Expand Down
6 changes: 4 additions & 2 deletions types/axios-token-interceptor/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosRequestConfig } from "axios";
import { AxiosInstance } from "axios";

// Module
declare function AxiosTokenProvider(Options: AxiosTokenProvider.InterceptorOptions): AxiosTokenProvider.TokenProvider;
Expand All @@ -18,7 +18,9 @@ declare namespace AxiosTokenProvider {
expires_in: number;
}

type TokenProvider = (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
type _InterceptorsRequestUseParam = Parameters<AxiosInstance["interceptors"]["request"]["use"]>[0];
type InternalAxiosRequestConfig = Parameters<NonNullable<_InterceptorsRequestUseParam>>[0];
type TokenProvider = (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig>;

interface TokenCacheOptions<T = unknown> {
getMaxAge?: (() => number) | ((el: T) => number) | undefined;
Expand Down
2 changes: 1 addition & 1 deletion types/axios-token-interceptor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"owners": [
{
"name": "Vivint Team Innovation",
"githubUsername": "innovation-team"
"githubUsername": "team-innovation"
},
{
"name": "Mike Dodge",
Expand Down

0 comments on commit 2ec8a47

Please sign in to comment.