When adding resolvedMembers ensure lateBoundSymbol is added whether it was previously checked or not#30970
Conversation
…he late bound member symbol is declared symbol containing the node. Ensure that resolvedMembers adds the late bound symbol even when its resolved sunce lateBoundMember may or may not be added to resolved members depending on when its checked Fixes #30891
sandersn
left a comment
There was a problem hiding this comment.
Looks good as far as I understand it but I have one question before signing off.
| return links.resolvedSymbol = lateSymbol; | ||
| } | ||
| } | ||
| else { |
There was a problem hiding this comment.
when does this case happen? lateSymbols is created in getResolvedMembersOrExportsOfSymbol, so I think it can only happen when the same name happens twice (or more) during the same for (const decl of symbol.declarations) loop. What is code that would have this structure?
There was a problem hiding this comment.
Is it two declarations with properties of the same name that should merge?
There was a problem hiding this comment.
In this case the interface HKT is defined in two files as extension of each other. If hkt is type checked, since that's the first declaration, we will get merged symbol => get resolved members on that symbol and things should work fine when resolving alias since HKT will use merged symbol.
Now in incremental scenarios or editor when hkt is not type checked, while typechecking hkt extended in main.ts, the parent = symbol of declaration of hkt interface in main.ts. While typechecking properties, the lateSymbol is bound and set in resolvedMembers of HKT interface declaration in main.ts.
But when resolving alias, we get merged symbol and late bound symbol has already a symbol but its not added to the merged symbol's resolvedMembers.
|
@sheetalkamat wanna add a // @strict: true
// @target: es6
const FOO_SYMBOL = Symbol('Foo');
declare global {
interface Promise<T> {
[FOO_SYMBOL]?: number;
}
}
export function foo<T>(p: Promise<T>) {
p[FOO_SYMBOL] = 3;
}compiler test and then mark #28334 as fixed as well? |
When interfaces are merged, always ensure that the parent symbol of the late bound member symbol is declared symbol of containing the node.
Ensure that resolvedMembers adds the late bound symbol even when its resolved as lateBoundMember may or may not be added to resolved members depending on when its checked and how the symbols are resolved.
Fixes #30891