Example from Chapter 6.2

Topics: Language Specification
Dec 6, 2013 at 5:59 PM
In chapter 6.2, the following example can be found:
function attr(name: string): string; 
function attr(name: string, value: string): Accessor; 
function attr(map: any): Accessor; 
function attr(nameOrMap: any, value?: string): any { 
    if (nameOrMap && typeof nameOrMap === "object") { 
        // handle map case 
    } 
    else { 
        // handle string case 
    } 
} 
Isn't the "implementation" with the comments incorrect? For example, calling attr(true) should fall under the map case since the name case requires a string, while map can work with any type. But by checking for typeof nameOrMap === "object", boolean literals (and others) will be treated as the string case.

I believe the example should look like this:
function attr(name: string): string; 
function attr(name: string, value: string): Accessor; 
function attr(map: any): Accessor; 
function attr(nameOrMap: any, value?: string): any { 
    if (nameOrMap && typeof nameOrMap === "string") { 
        // handle string case 
    } 
    else { 
        // handle map case 
    } 
} 
Coordinator
Dec 6, 2013 at 6:51 PM
I think you might be right. Copying to a work item to follow up.
Coordinator
Dec 6, 2013 at 6:52 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.