dojo / core

:rocket: Dojo 2 - language helpers and utilities.
http://dojo.io
Other
213 stars 58 forks source link

UrlSearchParams toString() should not add queryParams if they have no value set #385

Open krezovic opened 6 years ago

krezovic commented 6 years ago

Enhancement

Package Version: Beta 5

Say that I have search view that has different fields and all are optional. Due to usage of typescript, I need to provide an interface which contains all the fields, but not all fields need to be set (they're undefined if they're not set).

Current implementation of UrlSearchParams appends keys without any value, which is undesired behaviour.

Say that I have (pseudo code, not actually tested, and I can't provide actual code)

interface Foo { bar: string; baz: string; }

const foo: Partial = { bar: 'baz' };

const params = new UrlSearchParams(foo);

params.toString() =>

baz&bar=baz

I believe the "baz" should not be shown at all in the resulting string.