Fix @implements emit for namespaced base types#38688
Conversation
1. Switch to isSymbolAccessible for both types and values, then unify to a single function. 2. Remove inaccesible base error. We can put it back after making @implements type reference lookup looser (which may or may not happen).
|
@weswigham I decided to try isSymbolAccessible for everything, and it passes all of suite 0. What additional tests even use d.ts emit? We don't have good coverage here. |
src/compiler/checker.ts
Outdated
| if (ref) { | ||
| return ref; | ||
| } | ||
| return createExpressionWithTypeArguments(/*typeArgs*/ undefined, symbolToExpression(t.symbol, context, SymbolFlags.Type)); |
There was a problem hiding this comment.
If t.symbol is undefined (which is often can be), I'm pretty sure this crashes? Or makes a node which'll crash later?
weswigham
left a comment
There was a problem hiding this comment.
I like how this looks now, though I am concerned with the unguarded t.symbol reference (since it only actually exists on anonymous object types and interface types).
JS |
|
This PR appears to be approved, but not merged yet. Is there anything I could help out with to get this over the line? Not sure how best we could test this in our repository, I assume we need it packed for that? |
|
Sorry, casualty of some urgent internal work that came up. I'll see if I can address @weswigham's comment about undefined |
Fixes #38640
Couple of outstanding questions:
require--requiredoesn't create a real alias today, but a value, which cannot be used forimplements.serializeImplementedTypecontains a duplicate oftrySerializeTypeReference, except that it callsisTypeSymbolAccessibleinstead ofgetSymbolAccessibilityChain. Both should call the same function, and then the code should be de-duped. But I'm not at all sure whethergetSymbolAccessibilityChainshould be expanded or whether both should call ofisSymbolAccessible.If (1) is impossible, then I can delete a lot of error reporting machinery that I currently haven't found a way to test.
Here's some more detail:
Inaccessible base type
@implements' type reference doesn't seem to addValueto name lookup the way the rest of jsdoc lookups do. I'm not sure why yet. However, chrome-devtools is referring to types from a .d.ts or global classes, as far as I know. However, the following code should probably work too:I just don't think there's much demand for that, considering that I didn't observe much usage of
@implementsoutside closure codebases, and if people write new jsdoc, they can work around the limitation for now by creating a type alias for the type of the class:@typedef C {typeof import('m').C}.Duplication in serializeImplementedType
I'm going to try switching
trySerializeTypeReferencetoisValueSymbolAccessible, and passallowModules: false.