Fix incorrect uritemplate typings

This commit is contained in:
Ruben Taelman
2017-10-31 10:38:09 +09:00
parent 00cb71a36a
commit a2cdbb8d73
2 changed files with 33 additions and 48 deletions
+27 -42
View File
@@ -1,6 +1,7 @@
// Type definitions for URI Template JS 0.3.4
// Project: https://github.com/fxa/uritemplate-js
// Definitions by: Chui Tey <https://github.com/teyc>
// Ruben Taelman <https://github.com/rubensworks>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/*
@@ -8,49 +9,33 @@
Available via the MIT license.
*/
declare namespace uritemplate {
interface UriTemplate {
/**
* Expands template into a string using parameter
* supplied
*/
expand(data: {}): string;
}
interface UriTemplateErrorOptions {
expressionText: string
message: string
position: number
}
interface UriTemplateError {
new (options: UriTemplateErrorOptions): UriTemplateError
}
interface UriTemplateStatic {
/**
* parse template text returning instance of UriTemplate
* @param template text
* @return instance of UriTemplate
* @example
* import UriTemplate = require('uritemplate');
* let template = UriTemplate.parse('http://localhost/query{?name,city}');
* let result = template.expand({name: 'Jayden', city: 'Wodonga'});
* // returns http://localhost/query?name=Jayden&city=Wodonga
*/
parse(templateText: string): uritemplate.UriTemplate;
UriTemplateError: new (options: uritemplate.UriTemplateErrorOptions) => uritemplate.UriTemplateError;
}
export class UriTemplate {
/**
* Expands template into a string using parameter
* supplied
*/
expand(data: {}): string;
}
declare module 'uritemplate' {
export var UriTemplate: uritemplate.UriTemplateStatic;
interface UriTemplateErrorOptions {
expressionText: string
message: string
position: number
}
export class UriTemplateError {
constructor(options: UriTemplateErrorOptions);
}
/**
* parse template text returning instance of UriTemplate
* @param template text
* @return instance of UriTemplate
* @example
* import UriTemplate = require('uritemplate');
* let template = UriTemplate.parse('http://localhost/query{?name,city}');
* let result = template.expand({name: 'Jayden', city: 'Wodonga'});
* // returns http://localhost/query?name=Jayden&city=Wodonga
*/
export function parse(templateText: string): UriTemplate;
+6 -6
View File
@@ -1,28 +1,28 @@
import { UriTemplate } from 'uritemplate';
import {parse as parseUriTemplate, UriTemplate, UriTemplateError} from "uritemplate";
function test_uritemplate() {
// syntax check: UriTemplate.parse
var template = UriTemplate.parse('http://localhost/categories{/categoryId}{?sort,pageNumber}');
var template: UriTemplate = parseUriTemplate('http://localhost/categories{/categoryId}{?sort,pageNumber}');
// syntax check: template.expand
var url = template.expand({
var url: string = template.expand({
categoryId : 'shoes',
sort: 'price',
pageNumber: 8
});
// import module check
var expectedUrl = 'http://localhost/categories/shoes?sort=price&pageNumber=8';
var expectedUrl: string = 'http://localhost/categories/shoes?sort=price&pageNumber=8';
if (expectedUrl != url) {
throw `Expected ${expectedUrl}, got ${url}`;
} else {
console.log('Test passed');
}
// syntax check: new UriTemplate.UriTemplateError
let error = new UriTemplate.UriTemplateError({
// syntax check: new UriTemplateError
let error: UriTemplateError = new UriTemplateError({
expressionText: 'error expression',
message: 'error message',
position: 5