Skip to content

Commit 572c96b

Browse files
committed
Update ModelReferenceResolver to support overload indexes
1 parent 1c1420d commit 572c96b

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

apps/api-extractor-model/src/model/ModelReferenceResolver.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DocDeclarationReference } from '@microsoft/tsdoc';
4+
import { DocDeclarationReference, SelectorKind } from '@microsoft/tsdoc';
55
import { ApiItem } from '../items/ApiItem';
66
import { ApiModel } from './ApiModel';
77
import { ApiPackage } from './ApiPackage';
88
import { ApiEntryPoint } from './ApiEntryPoint';
99
import { ApiItemContainerMixin } from '../mixins/ApiItemContainerMixin';
10+
import { ApiParameterListMixin } from '../mixins/ApiParameterListMixin';
1011

1112
/**
1213
* Result object for {@link ApiModel.resolveDeclarationReference}.
@@ -108,7 +109,31 @@ export class ModelReferenceResolver {
108109
return result;
109110
}
110111
if (foundMembers.length > 1) {
111-
// TODO: Support TSDoc selectors
112+
if (memberReference.selector && memberReference.selector.selectorKind === SelectorKind.Index) {
113+
const selectedMembers: ApiItem[] = [];
114+
115+
const selectorOverloadIndex: number = parseInt(memberReference.selector.selector);
116+
for (const foundMember of foundMembers) {
117+
if (ApiParameterListMixin.isBaseClassOf(foundMember)) {
118+
if (foundMember.overloadIndex === selectorOverloadIndex) {
119+
selectedMembers.push(foundMember);
120+
}
121+
}
122+
}
123+
124+
if (selectedMembers.length === 0) {
125+
result.errorMessage = `An overload for ${JSON.stringify(identifier)} was not found that matches`
126+
+ ` the TSDoc selector ":${selectorOverloadIndex}"`;
127+
return result;
128+
}
129+
130+
if (selectedMembers.length === 1) {
131+
result.resolvedApiItem = selectedMembers[0];
132+
return result;
133+
}
134+
}
135+
136+
// TODO: Support other TSDoc selectors
112137
result.errorMessage = `The member reference ${JSON.stringify(identifier)} was ambiguous` ;
113138
return result;
114139
}

0 commit comments

Comments
 (0)