soywiz-archive / typescript-node-definitions

TypeScript's typings for some popular node.js modules
207 stars 93 forks source link

url.Url.query is many-typed #49

Closed bobappleyard closed 10 years ago

bobappleyard commented 10 years ago

Classic TypeScript problem here. A JavaScript function has taken advantage of dynamic typing and TypeScript can't represent it.


Parsing url normally

> require('url').parse('/?a=1')
{ ...
  query: "a=1",
  ... }

Parse it with query parsing switched on

> require('url').parse('/?a=1', true)
{ ...
  query: {a: '1'},
  ... }

Parse it with multiple instances of an a parameter

> require('url').parse('/?a=1&a=2', true)
{ ...
  query: {a: ['1', '2']}
  ... }

I propose changing this field to any. It sucks but we can't do any better right now.

Maybe one day a sum type that can express this sort of thing will make its way into the language.

A pull request will be forthcoming.