Fix prototype property type lookup#33034
Conversation
I knew I missed some code in the constructor-functions-as-classes PR. This simplifies the type reference resolution code as well.
|
@andrewbranch @PranavSenthilnathan you might be interested in this. Pranav, I remember you made the last edit to the documentation of getTypeFromJSAlias. It's used only for aliases now, so much of the previous text didn't apply anymore. |
|
@orta might be interested in looking at it too after he gets back, since he fixed a couple expando-related bugs recently. |
| const valueType = getTypeOfSymbol(symbol); | ||
| const typeType = | ||
| valueType.symbol && | ||
| valueType.symbol !== symbol && // Make sure this is a commonjs export by checking that symbol -> type -> symbol doesn't roundtrip. |
There was a problem hiding this comment.
We do have tests that still fall thru and use this function, right?
There was a problem hiding this comment.
Yes, about 6. None of them are classes anymore, though.
There was a problem hiding this comment.
Believe me, I tried deleting it to make sure. =P
sandersn
left a comment
There was a problem hiding this comment.
Some explanations of what changed.
| const type = getTypeReferenceTypeWorker(node, symbol, typeArguments); | ||
| if (type) { | ||
| return type; | ||
| if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { |
There was a problem hiding this comment.
these two cases are all that's left of getTypeReferenceTypeWorker
| if (symbol === unknownSymbol) { | ||
| return errorType; | ||
| } | ||
| symbol = getExpandoSymbol(symbol) || symbol; |
There was a problem hiding this comment.
getExpandoSymbol takes care of the JS special cases that used to be in getTypeReferenceTypeWorker; then you just treat them like normal symbols afterward.
| if (resolved.callSignatures.length === 1) { | ||
| return getReturnTypeOfSignature(resolved.callSignatures[0]); | ||
| } | ||
| function getTypeFromJSAlias(node: NodeWithTypeArguments, symbol: Symbol): Type | undefined { |
There was a problem hiding this comment.
new name for getJSDocTypeReference, reflecting its reduced responsibilities.
* Fix constructor function type reference lookup I knew I missed some code in the constructor-functions-as-classes PR. This simplifies the type reference resolution code as well. * Simplify and document js alias type resolution
This removes over half of the weird code for supporting JS in getTypeReferenceType. Lookup of commonjs aliases is still there and still weird, but I improved the documentation a little.
Fixes #33013