Print js-constructor function type names#23089
Conversation
Instead of printing them as a type literal, which is scary.
| exports.n.K = function () { | ||
| >exports.n.K = function () { this.x = 10;} : () => void | ||
| >exports.n.K : () => void | ||
| >exports.n.K = function () { this.x = 10;} : typeof (Anonymous function) |
There was a problem hiding this comment.
Rather than (Anonymous function), can we wire this up so it has name K?
There was a problem hiding this comment.
Yep, I'm working on it. I'm trying to understand the machinery that decides between K, n.K and exports.n.K.
That otherwise have no name. This helps quick info for javascript a *lot*. Typescript mainly benefits when printing the type of class expressions.
| else if (isPropertyAssignment(node.parent)) { | ||
| return node.parent.name; | ||
| } | ||
| else if (isBinaryExpression(node.parent) && node === node.parent.right) { |
There was a problem hiding this comment.
No love for binding pattern initializers?:
const {
a = function() {},
b = class {}
} = ({} as any);There was a problem hiding this comment.
Done! (But, no, I don't like binding pattern initializers)
|
Looks like I forgot to update some fourslash tests. I'll do that and then add support for binding pattern initializers. |
Also fix some fourslash baselines
weswigham
left a comment
There was a problem hiding this comment.
The changes to getNameOfDeclaration may impact services for the stuff that now has a name (likely in a good way, but I'm not sure). I'd keep an eye on it.
Instead of printing them as a type literal, which is scary.
Also, print the names of otherwise-anonymous functions and classes as the name of the declaration that they are assigned to:
In both Typescript and Javascript, we currently print "(Anonymous class)" for the type of
oc. After this change, we print it asC. This isn't perfect (the accessible symbol chain isn't there), but it's better than what we have.