[node] Narrow down type that can be passed to url.format(). (#16850)

* Narrow down type that can be passed to url.format().

* Add format(URL).

* [node] Fix build error.
universal-analytics package has invalid tslint.json.

* [node] Fix build error.
universal-analytics package has invalid version number.
This commit is contained in:
Leonard Thieu
2017-06-01 15:05:57 -04:00
committed by Mohamed Hegazy
parent 796bb77b68
commit 3f95ea32d7
5 changed files with 41 additions and 4 deletions

23
types/node/index.d.ts vendored
View File

@@ -1854,10 +1854,31 @@ declare module "url" {
path?: string;
}
export interface UrlObject {
protocol?: string;
slashes?: boolean;
auth?: string;
host?: string;
hostname?: string;
port?: string | number;
pathname?: string;
search?: string;
query?: { [key: string]: any; };
hash?: string;
}
export function parse(urlStr: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url;
export function format(url: Url): string;
export function format(URL: URL, options?: URLFormatOptions): string;
export function format(urlObject: UrlObject): string;
export function resolve(from: string, to: string): string;
export interface URLFormatOptions {
auth?: boolean;
fragment?: boolean;
search?: boolean;
unicode?: boolean;
}
export class URLSearchParams implements Iterable<string[]> {
constructor(init?: URLSearchParams | string | { [key: string]: string | string[] } | Iterable<string[]> );
append(name: string, value: string): void;

View File

@@ -415,6 +415,9 @@ namespace url_tests {
pathname: 'search',
query: { q: "you're a lizard, gary" }
});
const myURL = new url.URL('https://a:b@你好你好?abc#foo');
url.format(myURL, { fragment: false, unicode: true, auth: false });
}
{

View File

@@ -1801,8 +1801,21 @@ declare module "url" {
path?: string;
}
export interface UrlObject {
protocol?: string;
slashes?: boolean;
auth?: string;
host?: string;
hostname?: string;
port?: string | number;
pathname?: string;
search?: string;
query?: { [key: string]: any; };
hash?: string;
}
export function parse(urlStr: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url;
export function format(url: Url): string;
export function format(urlObject: UrlObject): string;
export function resolve(from: string, to: string): string;
}

View File

@@ -1,4 +1,4 @@
// Type definitions for universal-analytics v0.4.13
// Type definitions for universal-analytics 0.4
// Project: https://github.com/peaksandpies/universal-analytics
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>, Iker Pérez Brunelli <https://github.com/DarkerTV>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

View File

@@ -1,3 +1,3 @@
{
"extends": "../tslint.json"
"extends": "dtslint/dt.json"
}