docuri icon indicating copy to clipboard operation
docuri copied to clipboard

typescript definition file

Open arolson101 opened this issue 8 years ago • 5 comments

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

arolson101 avatar Nov 08 '16 16:11 arolson101

What is a typescript definition file?

jo avatar Nov 08 '16 20:11 jo

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>;
}

arolson101 avatar Nov 08 '16 20:11 arolson101

ok thanks, I'd accept a pull

jo avatar Nov 09 '16 09:11 jo

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.

wmaurer avatar Dec 01 '16 20:12 wmaurer

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>;
}

creativecoder avatar Jun 15 '18 02:06 creativecoder