I have some code where I'd like to be able to build query strings. Unfortunately I can't seem to find a polyfill similar to what I'm currently doing with fetch.
Is there any correct way to get these newer standards into my typescript projects, along with any actual polyfill code to accompany my build?
As indicated in the template, this is not a support forum. Please ask questions on Stack Overflow or similar sites.
This is not a question or support request.
I'm looking for an implementation of URLSearchParams to use in my TypeScript projects. Similar to how you offer other libraries via the --lib flag.
I don't understand what about that isn't a question. Are you saying there's a bug in TypeScript?
URLSearchParams is still an experimental feature. we do not add DOM libraries to the standard library at this stage to avoid breaking users in the future. that said, interfaces are interfaces, and do not need to be in lib.d.ts specifically. you would need to declare it:
declare class URLSearchParams {
/** Constructor returning a URLSearchParams object. */
constructor(init?: string| URLSearchParams);
/**Appends a specified key/value pair as a new search parameter. */
append(name: string, value: string): void
/** Deletes the given search parameter, and its associated value, from the list of all search parameters. */
delete(name: string): void;
/** Returns an iterator allowing to go through all key/value pairs contained in this object. */
entries(): IterableIterator<[string, string]>;
/** Returns the first value associated to the given search parameter. */
get(name: string): string;
/** Returns all the values association with a given search parameter. */
getAll(name: string): string[];
/** Returns a Boolean indicating if such a search parameter exists. */
has(name: string): boolean;
/** Returns an iterator allowing to go through all keys of the key/value pairs contained in this object. */
keys(): IterableIterator<string>;
/** Sets the value associated to a given search parameter to the given value. If there were several values, delete the others. */
set(name: string, value: string): void;
/** Returns a string containg a query string suitable for use in a URL. */
toString(): string;
/** Returns an iterator allowing to go through all values of the key/ value pairs contained in this object. */
values(): IterableIterator<string>;
/** Iterator */
[Symbol.iterator](): IterableIterator<number>;
}
Should be fixed by https://github.com/Microsoft/TSJS-lib-generator/pull/167
@mhegazy This doesn't seem to be fixed in 2.1.4. I see it has the 2.2 milestone now. Is it available in nightly?
The fix is checked in the lib repo and needs to be ported in. We do them in patches; once it is in the nightly we will close the issue.
Thanks for the explanation.
Yay!
Most helpful comment
URLSearchParamsis still an experimental feature. we do not add DOM libraries to the standard library at this stage to avoid breaking users in the future. that said, interfaces are interfaces, and do not need to be inlib.d.tsspecifically. you would need to declare it: