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 typings #8

Closed
wants to merge 16 commits into from

Conversation

dudeofawesome
Copy link

No description provided.

index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated
*/
declare function readPkg(options?: IOptions): Promise<IPackage>;

declare namespace readPkg {
Copy link
Owner

Choose a reason for hiding this comment

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

In TS 3.1, we can now declare props on functions, so I don't think we need a namespace for this, see: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-1.html

Copy link
Author

Choose a reason for hiding this comment

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

I'm trying to get this style of definition to work, but I'm not sure how to translate their example (which is for a regular .ts file) to work with a definition file with an ambient context, where you can't make assignments.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I think you're right. Actually, we can just export the sync method as a named export.

Copy link
Author

Choose a reason for hiding this comment

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

Are you talking about like so?

export default function (options?: Options): Promise<PackageMetadata>;
export function sync (options?: Options): PackageMetadata;

I believe that would require a change to the JS if that's the plan.

Copy link
Owner

Choose a reason for hiding this comment

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

Yup, exactly like that.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, I think this is done too.

index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
index.test-d.ts Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

Very nice work. Thanks for taking the time to make it great. 🙌

index.test-d.ts Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

For packages with a default export, use export default foo;, not export = foo;. You will have to add module.exports.default = foo; to the index.js file. - https://github.com/sindresorhus/typescript-definition-style-guide

@sindresorhus
Copy link
Owner

You still need to do #8 (comment)

@sindresorhus
Copy link
Owner

@dudeofawesome Ping :)

@sindresorhus
Copy link
Owner

@dudeofawesome Still interested in finishing this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants