-
Notifications
You must be signed in to change notification settings - Fork 10
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
Comments
What is a typescript definition file? |
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:
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>;
} |
ok thanks, I'd accept a pull |
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. |
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>;
} |
Would you be open to adding a typescript definition file to your repository? I can create one for you
The text was updated successfully, but these errors were encountered: