-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix @implements emit for namespaced base types #38688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If t.symbol
is undefined
(which is often can be), I'm pretty sure this crashes? Or makes a node which'll crash later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
--require
doesn't create a real alias today, but a value, which cannot be used forimplements
.serializeImplementedType
contains a duplicate oftrySerializeTypeReference
, except that it callsisTypeSymbolAccessible
instead ofgetSymbolAccessibilityChain
. Both should call the same function, and then the code should be de-duped. But I'm not at all sure whethergetSymbolAccessibilityChain
should 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 addValue
to 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
@implements
outside 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
trySerializeTypeReference
toisValueSymbolAccessible
, and passallowModules: false
.