build: ts-api-guardian should support interface with value types (#27223)

This fixes an issue where a value would hide the type.

```
export interface Foo {
  someMethod(): void;
}

export const Foo: Function = ...;
```

In the above example the `Foo` constant will hide the `interface Foo` symbol.
This change properly saves the interface in addition to the type.

PR Close #27223
This commit is contained in:
Miško Hevery
2018-11-26 14:44:45 -08:00
committed by Jason Aden
parent 23b06af940
commit 60e403bf6d
10 changed files with 252 additions and 139 deletions

View File

@ -50,7 +50,7 @@ export const ANALYZE_FOR_ENTRY_COMPONENTS = new InjectionToken<any>('AnalyzeForE
/**
* Type of the Attribute decorator / constructor function.
*
*
* @publicApi
*/
export interface AttributeDecorator {
/**
@ -99,6 +99,8 @@ export interface AttributeDecorator {
/**
* Type of the Attribute metadata.
*
* @publicApi
*/
export interface Attribute { attributeName?: string; }
@ -113,6 +115,8 @@ export const Attribute: AttributeDecorator =
/**
* Type of the Query metadata.
*
* @publicApi
*/
export interface Query {
descendants: boolean;
@ -181,6 +185,7 @@ export interface ContentChildrenDecorator {
*
*
* @Annotation
* @publicApi
*/
export type ContentChildren = Query;
@ -237,7 +242,7 @@ export interface ContentChildDecorator {
*
* @see `ContentChild`.
*
*
* @publicApi
*/
export type ContentChild = Query;
@ -246,6 +251,7 @@ export type ContentChild = Query;
*
*
* @Annotation
*
* @publicApi
*/
export const ContentChild: ContentChildDecorator = makePropDecorator(
@ -293,6 +299,8 @@ export interface ViewChildrenDecorator {
/**
* Type of the ViewChildren metadata.
*
* @publicApi
*/
export type ViewChildren = Query;
@ -359,6 +367,8 @@ export interface ViewChildDecorator {
/**
* Type of the ViewChild metadata.
*
* @publicApi
*/
export type ViewChild = Query;

View File

@ -77,23 +77,31 @@ export interface DirectiveDecorator {
new (obj: Directive): Directive;
}
/**
* Directive decorator and metadata.
*
* @Annotation
* @publicApi
*/
export interface Directive {
/**
* The CSS selector that triggers the instantiation of a directive.
* The CSS selector that identifies this directive in a template
* and triggers instantiation of the directive.
*
* Declare as one of the following:
*
* - `element-name`: select by element name.
* - `.class`: select by class name.
* - `[attribute]`: select by attribute name.
* - `[attribute=value]`: select by attribute name and value.
* - `:not(sub_selector)`: select only if the element does not match the `sub_selector`.
* - `selector1, selector2`: select if either `selector1` or `selector2` matches.
* - `element-name`: Select by element name.
* - `.class`: Select by class name.
* - `[attribute]`: Select by attribute name.
* - `[attribute=value]`: Select by attribute name and value.
* - `:not(sub_selector)`: Select only if the element does not match the `sub_selector`.
* - `selector1, selector2`: Select if either `selector1` or `selector2` matches.
*
* Angular only allows directives to trigger on CSS selectors that do not cross element
* boundaries. For example, consider a directive with an `input[type=text]` selector.
* For the following HTML, the directive is instantiated only on the
* `<input type="text">` element.
* Angular only allows directives to apply on CSS selectors that do not cross
* element boundaries.
*
* For the following template HTML, a directive with an `input[type=text]` selector,
* would be instantiated only on the `<input type="text">` element.
*
* ```html
* <form>
@ -176,8 +184,9 @@ export interface Directive {
outputs?: string[];
/**
* A set of injection tokens that allow the DI system to
* provide a dependency to this directive or component.
* Configures the [injector](guide/glossary#injector) of this
* directive or component with a [token](guide/glossary#di-token)
* that maps to a [provider](guide/glossary#provider) of a dependency.
*/
providers?: Provider[];
@ -247,62 +256,6 @@ export interface Directive {
*/
queries?: {[key: string]: any};
/**
* If true, this directive/component will be skipped by the AOT compiler and so will always be
* compiled using JIT.
*
* This exists to support future Ivy work and has no effect currently.
*/
jit?: true;
}
/**
* Directive decorator and metadata.
*
* @Annotation
*/
export interface Directive {
/**
* The CSS selector that identifies this directive in a template
* and triggers instantiation of the directive.
*
* Declare as one of the following:
*
* - `element-name`: Select by element name.
* - `.class`: Select by class name.
* - `[attribute]`: Select by attribute name.
* - `[attribute=value]`: Select by attribute name and value.
* - `:not(sub_selector)`: Select only if the element does not match the `sub_selector`.
* - `selector1, selector2`: Select if either `selector1` or `selector2` matches.
*
* Angular only allows directives to apply on CSS selectors that do not cross
* element boundaries.
*
* For the following template HTML, a directive with an `input[type=text]` selector,
* would be instantiated only on the `<input type="text">` element.
*
* ```html
* <form>
* <input type="text">
* <input type="radio">
* <form>
* ```
*
*/
selector?: string;
/**
* The set of event-bound output properties.
* When an output property emits an event, an event handler attached
* to that event in the template is invoked.
*
* Each output property maps a `directiveProperty` to a `bindingProperty`:
* - `directiveProperty` specifies the component property that emits events.
* - `bindingProperty` specifies the HTML attribute the event handler is attached to.
*
*/
outputs?: string[];
/**
* Maps class properties to host element bindings for properties,
* attributes, and events, using a set of key-value pairs.
@ -328,27 +281,12 @@ export interface Directive {
host?: {[key: string]: string};
/**
* Configures the [injector](guide/glossary#injector) of this
* directive or component with a [token](guide/glossary#di-token)
* that maps to a [provider](guide/glossary#provider) of a dependency.
*/
providers?: Provider[];
/**
* The name or names that can be used in the template to assign this directive to a variable.
* For multiple names, use a comma-separated string.
* If true, this directive/component will be skipped by the AOT compiler and so will always be
* compiled using JIT.
*
* This exists to support future Ivy work and has no effect currently.
*/
exportAs?: string;
/**
* Configures the queries that will be injected into the directive.
*
* Content queries are set before the `ngAfterContentInit` callback is called.
* View queries are set before the `ngAfterViewInit` callback is called.
*
*/
queries?: {[key: string]: any};
jit?: true;
}
/**
@ -512,6 +450,8 @@ export interface ComponentDecorator {
/**
* Supplies configuration metadata for an Angular component.
*
* @publicApi
*/
export interface Component extends Directive {
/**
@ -645,6 +585,8 @@ export interface PipeDecorator {
/**
* Type of the Pipe metadata.
*
* @publicApi
*/
export interface Pipe {
/**
@ -704,7 +646,7 @@ export interface InputDecorator {
/**
* Type of metadata for an `Input` property.
*
*
* @publicApi
*/
export interface Input {
/**
@ -824,6 +766,8 @@ export interface OutputDecorator {
/**
* Type of the Output metadata.
*
* @publicApi
*/
export interface Output { bindingPropertyName?: string; }
@ -879,6 +823,7 @@ export interface HostBindingDecorator {
/**
* Type of the HostBinding metadata.
*
* @publicApi
*/
export interface HostBinding { hostPropertyName?: string; }
@ -902,6 +847,8 @@ export interface HostListenerDecorator {
/**
* Type of the HostListener metadata.
*
* @publicApi
*/
export interface HostListener {
/**

View File

@ -127,6 +127,8 @@ export interface NgModuleDecorator {
/**
* Type of the NgModule metadata.
*
* @publicApi
*/
export interface NgModule {
/**

View File

@ -20,6 +20,9 @@ const UNDEFINED = new Object();
let _nextRootElementId = 0;
/**
* @publicApi
*/
export interface TestBed {
platform: PlatformRef;
@ -35,16 +38,12 @@ export interface TestBed {
*
* Test modules and platforms for individual platforms are available from
* '@angular/<platform_name>/testing'.
*
* @publicApi
*/
initTestEnvironment(
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
/**
* Reset the providers for the test injector.
*
* @publicApi
*/
resetTestEnvironment(): void;
@ -119,8 +118,6 @@ export class TestBedViewEngine implements Injector, TestBed {
*
* Test modules and platforms for individual platforms are available from
* '@angular/<platform_name>/testing'.
*
* @publicApi
*/
static initTestEnvironment(
ngModule: Type<any>|Type<any>[], platform: PlatformRef,
@ -132,8 +129,6 @@ export class TestBedViewEngine implements Injector, TestBed {
/**
* Reset the providers for the test injector.
*
* @publicApi
*/
static resetTestEnvironment(): void { _getTestBedViewEngine().resetTestEnvironment(); }
@ -291,8 +286,6 @@ export class TestBedViewEngine implements Injector, TestBed {
*
* Test modules and platforms for individual platforms are available from
* '@angular/<platform_name>/testing'.
*
* @publicApi
*/
initTestEnvironment(
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void {
@ -308,8 +301,6 @@ export class TestBedViewEngine implements Injector, TestBed {
/**
* Reset the providers for the test injector.
*
* @publicApi
*/
resetTestEnvironment(): void {
this.resetTestingModule();