Skip to content

Commit 3c01bbd

Browse files
CvXsindresorhus
authored andcommitted
Add TypeScript definition (#2)
1 parent c31211b commit 3c01bbd

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed

index.d.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
interface CommonOptions {
2+
/**
3+
* The issue body.
4+
*/
5+
readonly body?: string;
6+
7+
/**
8+
* The issue title.
9+
*/
10+
readonly title?: string;
11+
12+
/**
13+
* Use an [issue template](https://help.github.com/articles/manually-creating-a-single-issue-template-for-your-repository/).
14+
*
15+
* @example
16+
*
17+
* 'unicorn.md' // If you want to use a template at `ISSUE_TEMPLATE/unicorn.md`.
18+
*/
19+
readonly template?: string;
20+
21+
/**
22+
* The labels for the issue.
23+
*
24+
* *Requires the user to have the permission to add labels.*
25+
*/
26+
readonly labels?: string[];
27+
28+
/**
29+
* The milestone for the issue.
30+
*
31+
* *Requires the user to have the permission to add milestone.*
32+
*/
33+
readonly milestone?: string;
34+
35+
/**
36+
* The user to assign to the issue.
37+
*
38+
* *Requires the user to have the permission to add assignee.*
39+
*/
40+
readonly assignee?: string;
41+
42+
/**
43+
* The projects to add the issue to.
44+
* 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`.
45+
*
46+
* *Requires the user to have the permission to add projects.*
47+
*/
48+
readonly projects?: string[];
49+
}
50+
51+
interface RepoUrlOptions extends CommonOptions {
52+
/**
53+
* The full URL to the repo.
54+
*/
55+
readonly repoUrl: string;
56+
}
57+
58+
interface UserAndRepoOptions extends CommonOptions {
59+
/**
60+
* GitHub username or organization.
61+
*/
62+
readonly user: string;
63+
64+
/**
65+
* GitHub repo.
66+
*/
67+
readonly repo: string;
68+
}
69+
70+
/**
71+
* You are required to either specify the `repoUrl` option or both the `user` and `repo` options.
72+
*/
73+
export type Options = RepoUrlOptions | UserAndRepoOptions
74+
75+
/**
76+
* Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields.
77+
*
78+
* @example
79+
*
80+
* import newGithubIssueUrl from 'new-github-issue-url';
81+
* import opn from 'opn';
82+
*
83+
* const url = newGithubIssueUrl({
84+
* user: 'sindresorhus',
85+
* repo: 'new-github-issue-url',
86+
* body: '\n\n\n---\nI\'m a human. Please be nice.'
87+
* });
88+
* //=> 'https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.'
89+
*
90+
* // Then open it
91+
* opn(url);
92+
*/
93+
export default function newGithubIssueUrl(options: Options): string;

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ module.exports = (options = {}) => {
4141

4242
return url.toString();
4343
};
44+
45+
module.exports.default = module.exports;

index.test-d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {expectType} from 'tsd-check';
2+
import newGithubIssueUrl from '.';
3+
4+
expectType<string>(newGithubIssueUrl({
5+
repoUrl: 'https://github.com/sindresorhus/new-github-issue-url',
6+
body: 'test'
7+
}));
8+
9+
expectType<string>(newGithubIssueUrl({
10+
user: 'sindresorhus',
11+
repo: 'new-github-issue-url'
12+
}));

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=10"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd-check"
1717
},
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"index.d.ts"
2021
],
2122
"keywords": [
2223
"github",
@@ -32,6 +33,7 @@
3233
],
3334
"devDependencies": {
3435
"ava": "^0.25.0",
36+
"tsd-check": "^0.3.0",
3537
"xo": "^0.23.0"
3638
}
3739
}

0 commit comments

Comments
 (0)