Description
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:
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))
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?