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

Merged
merged 2 commits into from
May 22, 2019
Merged

Add types #8

merged 2 commits into from
May 22, 2019

Conversation

tylerodonnell
Copy link
Member

This PR adds a index.d.ts file to be used for typescript.

index.d.ts Outdated Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved

function Authentic(opts: AuthenticOpts): Validator

namespace Authentic {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason for the namespace here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to use a namespace so we're able to use a namespace import

import * as Authentic from "@articulate/authentic";

This allows users to still be able to do

import * as Authentic from "@articulate/authentic"
Authentic() // function
Authentic.JWT // interface
import authentic from "@articulate/authentic"
authentic() // function
import { JWT } from "@articulate/authentic"
JWT // interface

Copy link
Member Author

Choose a reason for hiding this comment

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

Without the namespace, you'll get an error in typscript: Cannot invoke an expression whose type lacks a call signature.

Copy link
Member

@vscerchia vscerchia left a comment

Choose a reason for hiding this comment

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

Left one question, but I think this looks good otherwise.

Not sure if you saw this, but I found this template on the typescript site: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html which I think would be want we want here except for the fact that we're exporting the function using module.exports instead of export = . This seems like a good first pass, though, since I don't think we're interested in changing the actual code if we can avoid it right now.

@tylerodonnell
Copy link
Member Author

@vscerchia Yeah I'm trying to leave the code alone with this PR. I'd love to make that suggestion in another version 👍

@tylerodonnell tylerodonnell merged commit f2ee4fc into master May 22, 2019
@tylerodonnell tylerodonnell deleted the types branch May 22, 2019 19:45
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