Skip to content

Variables of kind ConditionalExpression have defaultValue set to condition #401

Closed
@nicknisi

Description

@nicknisi

Given the following TypeScript code, TypeDoc produces some incorrect output.

Source File:

/**
 * some function
 * @param str some string
 * @returns true or false
 */
export const assign = has('something') ? function(str: string): boolean { return true; } : function (str: string): boolean { return false; };

Output:

screen shot 2017-02-01 at 9 13 03 am

What seems to be happening is that this is going through the variable converter, and inside of the switch statement, the node.initializer.kind value is 193 ("ConditionalExpression"). This means that it hits the default portion of the switch statement and sets the whole conditional as the defaultValue, which seems incorrect given TypeScript can determine the type for the conditional expression.

I know that TypeScript can determine what the actual type is for the assign variable.

context.checker.typeToString(context.checker.getTypeAtLocation(node.initializer))

screen shot 2017-02-01 at 9 19 10 am

I'm looking into how TypeDoc can infer this as well. What I am initially looking at is treating ConditionalExpression variable kinds as a special case in that case statement, and creating a new node converter to handle converting the conditional into a type. I'm still trying to determine how to create modify the variable reflection to have the correct type and be of the correct kind (the above screenshot should be marked as a function but it isn't) from the conditional. Does this sound like a reasonable approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions