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

Add TypeScript definition #13

Merged
merged 10 commits into from Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions index.d.ts
@@ -0,0 +1,23 @@
export interface ShellEnv {
Fazendaaa marked this conversation as resolved.
Show resolved Hide resolved
readonly [x: string]: string;
Fazendaaa marked this conversation as resolved.
Show resolved Hide resolved
readonly SHELL: string;
readonly TERM_PROGRAM: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are no guaranteed to exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

}

/**
* Get the environment variables defined in your dotfiles.
*
* @param shell To read the environment variables from.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the default value.

* @returns The environment variables.
*/
export function sync(shell?: string): ShellEnv;

/**
* Get the environment variables defined in your dotfiles.
*
* @param shell To read the environment variables from.
Fazendaaa marked this conversation as resolved.
Show resolved Hide resolved
* @returns The environment variables.
*/
export function shellEnv(shell?: string): Promise<ShellEnv>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a default export only, not a named export too.


export default shellEnv;
7 changes: 7 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,7 @@
import {expectType} from 'tsd-check';
import shellEnv, { sync, ShellEnv } from '.';
Fazendaaa marked this conversation as resolved.
Show resolved Hide resolved

(async () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectType<ShellEnv>(sync());
expectType<ShellEnv>(await shellEnv());
})();
11 changes: 9 additions & 2 deletions package.json
Expand Up @@ -13,10 +13,11 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"env",
Expand All @@ -39,6 +40,12 @@
},
"devDependencies": {
"ava": "*",
"tsd-check": "^0.2.1",
"xo": "*"
},
"xo": {
"ignores": [
"*.ts"
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

}
}