From 44d40c8eca7422815eaf6f0e40e0be6d9ec78f52 Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Wed, 31 Mar 2021 12:55:39 -0700 Subject: [PATCH 1/2] test: `auth` resolve type should be discrimated based on options passed to `auth()` --- test/typescript-validate.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/typescript-validate.ts b/test/typescript-validate.ts index 9734eddf0..289be1a28 100644 --- a/test/typescript-validate.ts +++ b/test/typescript-validate.ts @@ -4,6 +4,8 @@ import { createAppAuth } from "../src"; +function expectType(what: T) {} + export async function readmeExample() { const auth = createAppAuth({ appId: 1, @@ -13,5 +15,7 @@ export async function readmeExample() { }); // Retrieve an oauth-access token - await auth({ type: "oauth-user", code: "123456" }); + const userAuthentication = await auth({ type: "oauth-user", code: "123456" }); + + expectType<"token">(userAuthentication.type); } From 414137da55d05af0835faf99438f52f2f24047ac Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Wed, 31 Mar 2021 12:57:33 -0700 Subject: [PATCH 2/2] test: reproduction for #268 --- test/typescript-validate.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/typescript-validate.ts b/test/typescript-validate.ts index 289be1a28..f301e1aa5 100644 --- a/test/typescript-validate.ts +++ b/test/typescript-validate.ts @@ -6,16 +6,24 @@ import { createAppAuth } from "../src"; function expectType(what: T) {} -export async function readmeExample() { - const auth = createAppAuth({ - appId: 1, - privateKey: "-----BEGIN PRIVATE KEY-----\n...", - clientId: "lv1.1234567890abcdef", - clientSecret: "1234567890abcdef12341234567890abcdef1234", - }); +const auth = createAppAuth({ + appId: 1, + privateKey: "-----BEGIN PRIVATE KEY-----\n...", + clientId: "lv1.1234567890abcdef", + clientSecret: "1234567890abcdef12341234567890abcdef1234", +}); +export async function readmeExample() { // Retrieve an oauth-access token const userAuthentication = await auth({ type: "oauth-user", code: "123456" }); expectType<"token">(userAuthentication.type); } + +export async function issue268() { + // Retrieve an oauth-access token + const userAuthentication = await auth({ type: "installation" }); + + expectType<"token">(userAuthentication.type); + expectType<"tokenType">(userAuthentication.tokenType); +}