TS v0.9 does not allow 'undefined' type - how to fix

Topics: Language Specification
Jun 21, 2013 at 11:03 PM
In the Google Map TS definition file, it has the following :
setValues(values: any): void;
setValues(values: undefined);

This is the definition for a google map v3 js API method : setValues(values:Object|undefined)

The above compiles fine in TS v0.8.3.1, but after I upgrade to v0.9, the compiler displays an error - "can not find symbol 'undefined'".

Is this a bug in the latest TS version or anything I should do to fix the definition file?
Jun 22, 2013 at 12:03 AM
This should be setValues(values?: any): void;

If you just omit the parameter, javascript will set the parameter as undefined.
Jun 24, 2013 at 4:11 PM
Isn't setValues(values: undefined); the same as setValues();?
Jun 24, 2013 at 4:33 PM
Grajkowski wrote:
Isn't setValues(values: undefined); the same as setValues();?
No; the correct way to indicate this signature in TypeScript is as nvivo suggested.
Jun 24, 2013 at 5:35 PM
markrendle wrote:
No; the correct way to indicate this signature in TypeScript is as nvivo suggested.
I think you misunderstood the question. I wasn't saying "use this type signature."
Coordinator
Jun 24, 2013 at 8:56 PM
@delpielo - right, as mentioned by some of the other people on the thread, if you want to say any|undefined, you use an optional argument (using the question mark).
setValues(values?: any): void;
Oct 9, 2013 at 1:00 AM
I have a similar problem:

I use some promises that have generic definitions (TS 0.9):
Promise<T>
The module that uses this and for which I'm writing a definition file has methods that return a promise for the value undefined.

But this is not accepted by the compiler:
append(path:string):Promise<undefined>;

//>> error TS2095: Could not find symbol 'undefined'
Obviously the optional ? is not usable there.

What do you advise to use here?

For now I go with any but is is not precise enough. I know exactly that is not just 'any' type but specifically will be 'undefined' (but what type is undefined? ehh? confusing :)
Oct 9, 2013 at 1:26 AM
Edited Oct 9, 2013 at 1:26 AM
I can answer my own question: it suddenly made sense.

If you have a method that has no explicit return value it is equal to returning the value undefined.

And how do you declare the return type for that function? As void!

Tried it in my generics and this compiles:
append(path:string):Promise<void>;
I leave this here for others who get this page as a search result.