Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 feat(typescript): discriminate resolve type of auth(options) based on options #270

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@

import { createAppAuth } from "../src";

function expectType<T>(what: T) {}

const auth = createAppAuth({
appId: 1,
privateKey: "-----BEGIN PRIVATE KEY-----\n...",
clientId: "lv1.1234567890abcdef",
clientSecret: "1234567890abcdef12341234567890abcdef1234",
});

export async function readmeExample() {
const auth = createAppAuth({
appId: 1,
privateKey: "-----BEGIN PRIVATE KEY-----\n...",
clientId: "lv1.1234567890abcdef",
clientSecret: "1234567890abcdef12341234567890abcdef1234",
});
// 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
await auth({ type: "oauth-user", code: "123456" });
const userAuthentication = await auth({ type: "installation" });

expectType<"token">(userAuthentication.type);
expectType<"tokenType">(userAuthentication.tokenType);
}