fix: overloading a function doesn't generate all of the signatures (#22569)

PR Close #22569
This commit is contained in:
Alan 2018-03-09 15:45:11 +01:00 committed by Kara Erickson
parent b5be18f405
commit e8326e600d
6 changed files with 32 additions and 3 deletions

View File

@ -303,7 +303,7 @@ export declare class NgLocaleLocalization extends NgLocalization {
/** @deprecated */ protected deprecatedPluralFn: ((locale: string, value: string | number) => Plural) | null | undefined; /** @deprecated */ protected deprecatedPluralFn: ((locale: string, value: string | number) => Plural) | null | undefined;
protected locale: string; protected locale: string;
constructor(locale: string, constructor(locale: string,
deprecatedPluralFn?: ((locale: string, value: string | number) => Plural) | null | undefined); /** @deprecated */ deprecatedPluralFn?: ((locale: string, value: string | number) => Plural) | null | undefined);
getPluralCategory(value: any, locale?: string): string; getPluralCategory(value: any, locale?: string): string;
} }

View File

@ -449,6 +449,7 @@ export declare const HostListener: HostListenerDecorator;
/** @experimental */ /** @experimental */
export declare function inject<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: undefined, flags?: InjectFlags): T; export declare function inject<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: undefined, flags?: InjectFlags): T;
export declare function inject<T>(token: Type<T> | InjectionToken<T>, notFoundValue: T | null, flags?: InjectFlags): T | null;
/** @stable */ /** @stable */
export declare const Inject: InjectDecorator; export declare const Inject: InjectDecorator;

View File

@ -156,3 +156,4 @@ export declare function withBody<T>(html: string, blockFn: T): T;
/** @experimental */ /** @experimental */
export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper; export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;
export declare function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;

View File

@ -5,6 +5,7 @@ export declare class RouterTestingModule {
/** @stable */ /** @stable */
export declare function setupTestingRouter(urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location, loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][], opts?: ExtraOptions, urlHandlingStrategy?: UrlHandlingStrategy): Router; export declare function setupTestingRouter(urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location, loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][], opts?: ExtraOptions, urlHandlingStrategy?: UrlHandlingStrategy): Router;
export declare function setupTestingRouter(urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location, loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][], urlHandlingStrategy?: UrlHandlingStrategy): Router;
/** @stable */ /** @stable */
export declare class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader { export declare class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {

View File

@ -215,7 +215,15 @@ class ResolvedDeclarationEmitter {
} }
} }
let children = node.getChildren(); let children: ts.Node[] = [];
if (ts.isFunctionDeclaration(node)) {
// Used ts.isFunctionDeclaration instead of node.kind because this is a type guard
const symbol = this.typeChecker.getSymbolAtLocation(node.name);
symbol.declarations.forEach(x => children = children.concat(x.getChildren()));
} else {
children = node.getChildren();
}
const sourceText = node.getSourceFile().text; const sourceText = node.getSourceFile().text;
if (children.length) { if (children.length) {
// Sort declarations under a class or an interface // Sort declarations under a class or an interface
@ -252,7 +260,7 @@ class ResolvedDeclarationEmitter {
.join(''); .join('');
// Print stability annotation for fields // Print stability annotation for fields
if (node.kind in memberDeclarationOrder) { if (ts.isParameter(node) || node.kind in memberDeclarationOrder) {
const trivia = sourceText.substr(node.pos, node.getLeadingTriviaWidth()); const trivia = sourceText.substr(node.pos, node.getLeadingTriviaWidth());
const match = stabilityAnnotationPattern.exec(trivia); const match = stabilityAnnotationPattern.exec(trivia);
if (match) { if (match) {

View File

@ -59,6 +59,24 @@ describe('unit test', () => {
check({'file.d.ts': input}, expected); check({'file.d.ts': input}, expected);
}); });
it('should support overloads functions', () => {
const input = `
export declare function group(steps: AnimationMetadata[], options?: AnimationOptions | null): AnimationGroupMetadata;
export declare function registerLocaleData(data: any, extraData?: any): void;
export declare function registerLocaleData(data: any, localeId?: string, extraData?: any): void;
`;
const expected = `
export declare function group(steps: AnimationMetadata[], options?: AnimationOptions | null): AnimationGroupMetadata;
export declare function registerLocaleData(data: any, extraData?: any): void;
export declare function registerLocaleData(data: any, localeId?: string, extraData?: any): void;
`;
check({'file.d.ts': input}, expected);
});
it('should ignore private props', () => { it('should ignore private props', () => {
const input = ` const input = `
export declare class A { export declare class A {