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

typescript definition file #49

Open
arolson101 opened this issue Nov 8, 2016 · 5 comments
Open

typescript definition file #49

arolson101 opened this issue Nov 8, 2016 · 5 comments

Comments

@arolson101
Copy link

Would you be open to adding a typescript definition file to your repository? I can create one for you

@jo
Copy link
Owner

jo commented Nov 8, 2016

What is a typescript definition file?

@arolson101
Copy link
Author

It's basically a file that helps typescript to know whether code is using the library correctly, and editors can use it for autocomplete and syntax checking. Documentation here

I created one locally, but by adding it to your repository (and modifying package.json to point to it) anyone using your library would get the definitions automatically. It looks like this:

docuri.d.ts:

declare module "docuri" {
    interface Route<T> {
        // parse DocURI string to object
        (str: string): T | false;

        // generate DocURI string from object
        (obj: T): string;

        // change DocURI string parts with values provided by object returning a string
        (str: string, obj: T): string;
    }

    export function route<T>(route: string): Route<T>;
}

@jo
Copy link
Owner

jo commented Nov 9, 2016

ok thanks, I'd accept a pull

@wmaurer
Copy link

wmaurer commented Dec 1, 2016

Thanks @arolson101, I'd also like to see this typescript definition file in the npm package. Since you've already done the work of creating the definition, do you want to make the pull request? If you don't, I could make the pull request, and naturally give you credit.

@creativecoder
Copy link

Here's my variation on a typescript definition file, in case you want to specify what kind of string is output.

declare module "docuri" {
  interface Route<RouteObj, RouteString> {
    // parse DocURI string to object
    (str: RouteString): RouteObj | false;

    // generate DocURI string from object
    (obj: RouteObj): RouteString;

    // change DocURI string parts with values provided by object returning a string
    (str: RouteString, obj: RouteObj): RouteString;
  }

  export function route<RouteObj, RouteString>(
    route: string,
  ): Route<RouteObj, RouteString>;
}

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

No branches or pull requests

4 participants