Merge pull request #32009 from BendingBender/new-github-issue-url

[new-github-issue-url] Add types
This commit is contained in:
Daniel Rosenwasser 2019-01-14 14:30:08 -08:00 committed by GitHub
commit 3449e8ee0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 159 additions and 0 deletions

81
types/new-github-issue-url/index.d.ts vendored Normal file
View File

@ -0,0 +1,81 @@
// Type definitions for new-github-issue-url 0.1
// Project: https://github.com/sindresorhus/new-github-issue-url#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export = newGithubIssueUrl;
/**
* Returns a URL string.
*/
declare function newGithubIssueUrl(options: newGithubIssueUrl.Options): string;
declare namespace newGithubIssueUrl {
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
type Options = XOR<RepoUrlOptions, UserRepoOptions>;
interface BaseOptions {
/**
* The issue body.
*/
body?: string;
/**
* The issue title.
*/
title?: string;
/**
* Use an [issue template](https://help.github.com/articles/manually-creating-a-single-issue-template-for-your-repository).
*
* For example, if you want to use a template at `ISSUE_TEMPLATE/unicorn.md`, you would specify `unicorn.md` here.
*/
template?: string;
/**
* The labels for the issue.
*
* *Requires the user to have the permission to add labels.*
*/
labels?: string[];
/**
* The milestone for the issue.
*
* *Requires the user to have the permission to add milestone.*
*/
milestone?: string;
/**
* The user to assign to the issue.
*
* *Requires the user to have the permission to add assignee.*
*/
assignee?: string;
/**
* The projects to add the issue to.
*
* The project reference format is `user/<project-number>`, for example, if the URL to the project
* is `https://github.com/sindresorhus/some-repo/projects/3`, the project reference would be `some-repo/3`.
*
* *Requires the user to have the permission to add projects.*
*/
projects?: string[];
}
interface RepoUrlOptions extends BaseOptions {
/**
* The full URL to the repo.
*/
repoUrl: string;
}
interface UserRepoOptions extends BaseOptions {
/**
* GitHub username or organization.
*/
user: string;
/**
* GitHub repo.
*/
repo: string;
}
}

View File

@ -0,0 +1,54 @@
import newGithubIssueUrl = require('new-github-issue-url');
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-issue-url.git',
});
// $ExpectType string
newGithubIssueUrl({
user: 'sindresorhus',
repo: 'new-github-issue-url',
});
// $ExpectError
newGithubIssueUrl({
user: 'sindresorhus',
});
// $ExpectError
newGithubIssueUrl({
repo: 'new-github-issue-url',
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
body: 'foo',
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
title: 'foo',
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
template: 'unicorn.md',
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
labels: ['foo', 'bar'],
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
milestone: 'foo',
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
assignee: 'sindresorhus',
});
// $ExpectType string
newGithubIssueUrl({
repoUrl: 'https://github.com/sindresorhus/new-github-release-url.git',
projects: ['some-repo/3'],
});

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"new-github-issue-url-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }