From ab7bbab368f40bc603877b31fa606b082d81637a Mon Sep 17 00:00:00 2001 From: Oscar Dominguez Date: Sat, 12 Mar 2022 22:46:53 +0100 Subject: [PATCH] test(types): add TS validation to assure types are properly configured --- test/typescript-validate.ts | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/typescript-validate.ts diff --git a/test/typescript-validate.ts b/test/typescript-validate.ts new file mode 100644 index 00000000..2051c4a6 --- /dev/null +++ b/test/typescript-validate.ts @@ -0,0 +1,51 @@ +import { Octokit } from "@octokit/core"; +import { throttling } from "../src/index"; +// ************************************************************ +// THIS CODE IS NOT EXECUTED. IT IS FOR TYPECHECKING ONLY +// ************************************************************ + +const octokit = new Octokit(); + +// will be deprecated soon +// onAbuseLimit() +throttling(octokit, { + throttle: { enabled: true, onRateLimit: () => {}, onAbuseLimit: () => {} }, +}); + +// onSecondaryLimit() +throttling(octokit, { + throttle: { + enabled: true, + onRateLimit: () => {}, + onSecondaryRateLimit: () => {}, + }, +}); + +// onSecondaryLimit() and onAbuseLimit() should be a TS Error +// @ts-expect-error +throttling(octokit, { + throttle: { + enabled: true, + onRateLimit: () => {}, + onSecondaryRateLimit: () => {}, + onAbuseLimit: () => {}, + }, +}); + +// onRateLimit() missing should be a TS Error +// @ts-expect-error +throttling(octokit, { + throttle: { + enabled: true, + onSecondaryRateLimit: () => {}, + }, +}); + +// onSecondaryLimit() and onAbuseLimit() missing should be a TS Error +throttling(octokit, { + // @ts-expect-error + throttle: { + enabled: true, + onRateLimit: () => {}, + }, +});