mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
Node: tighten URL query type (#33997)
* Add failing test * Fix failing test * Specify min version * Name type and export * Move type * Use interface * Use index signature * Relocate test, fix 2.0 support * Replace type alias with inline type + comments
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
e1be1d24b7
commit
d9f74cb42c
Vendored
+8
-1
@@ -10,7 +10,14 @@ declare module "querystring" {
|
||||
|
||||
interface ParsedUrlQuery { [key: string]: string | string[]; }
|
||||
|
||||
function stringify(obj?: {}, sep?: string, eq?: string, options?: StringifyOptions): string;
|
||||
interface ParsedUrlQueryInput {
|
||||
[key: string]:
|
||||
// The value type here is a "poor man's `unknown`". When these types support TypeScript
|
||||
// 3.0+, we can replace this with `unknown`.
|
||||
{} | null | undefined;
|
||||
}
|
||||
|
||||
function stringify(obj?: ParsedUrlQueryInput, sep?: string, eq?: string, options?: StringifyOptions): string;
|
||||
function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): ParsedUrlQuery;
|
||||
function escape(str: string): string;
|
||||
function unescape(str: string): string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as querystring from 'querystring';
|
||||
|
||||
interface SampleObject { a: string; }
|
||||
interface SampleObject { [key: string]: string; }
|
||||
|
||||
{
|
||||
const obj: SampleObject = { a: "" };
|
||||
@@ -40,3 +40,9 @@ interface SampleObject { a: string; }
|
||||
result = querystring.escape(str);
|
||||
result = querystring.unescape(str);
|
||||
}
|
||||
|
||||
{
|
||||
const queryInput: string | null | querystring.ParsedUrlQueryInput = {};
|
||||
// $ExpectError
|
||||
const query: string | null | querystring.ParsedUrlQuery = queryInput;
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
declare module "url" {
|
||||
import { ParsedUrlQuery } from 'querystring';
|
||||
import { ParsedUrlQuery, ParsedUrlQueryInput } from 'querystring';
|
||||
|
||||
interface UrlObjectCommon {
|
||||
auth?: string;
|
||||
@@ -17,7 +17,7 @@ declare module "url" {
|
||||
// Input to `url.format`
|
||||
interface UrlObject extends UrlObjectCommon {
|
||||
port?: string | number;
|
||||
query?: string | null | { [key: string]: any };
|
||||
query?: string | null | ParsedUrlQueryInput;
|
||||
}
|
||||
|
||||
// Output of `url.parse`
|
||||
|
||||
Reference in New Issue
Block a user