Skip to content

Commit 8e7bbc6

Browse files
authored
refactor: remove usages of the Component interface (#7077)
The `Component` interface provides no typesafety to description component classes. Its only purpose is to define the properties of the Component decorator. Currently it only has optional properties, so it matches the type `{}` which is as safe as `any`.
1 parent e6df954 commit 8e7bbc6

7 files changed

Lines changed: 21 additions & 26 deletions

File tree

tensorboard/webapp/app_routing/route_config_types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
import {Component, Type} from '@angular/core';
15+
import {Type} from '@angular/core';
16+
import {Action} from '@ngrx/store';
1617
import {DeepLinkProvider} from './deep_link_provider';
1718
import {RouteKind, SerializableQueryParams} from './types';
18-
import {Action} from '@ngrx/store';
1919

2020
export interface ConcreteRouteDef {
2121
routeKind: RouteKind;
@@ -26,7 +26,7 @@ export interface ConcreteRouteDef {
2626
// Parameter has to be denoted with ":" prefix and "/" has to precede it.
2727
path: string;
2828

29-
ngComponent: Type<Component>;
29+
ngComponent: Type<unknown>;
3030

3131
// Redirect to this `path` if current navigation does not match any known
3232
// routes. Only one RouteConfig can have defaultRoute = true.

tensorboard/webapp/app_routing/route_registry_module.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
import {
16-
Component,
1716
Inject,
1817
ModuleWithProviders,
1918
NgModule,
@@ -28,10 +27,7 @@ import {RouteKind} from './types';
2827
@NgModule({})
2928
export class RouteRegistryModule {
3029
private readonly routeConfigs: RouteConfigs;
31-
private readonly routeKindToNgComponent = new Map<
32-
RouteKind,
33-
Type<Component>
34-
>();
30+
private readonly routeKindToNgComponent = new Map<RouteKind, Type<unknown>>();
3531

3632
constructor(
3733
@Optional() @Inject(ROUTE_CONFIGS_TOKEN) configsList: RouteDef[][]
@@ -67,7 +63,7 @@ export class RouteRegistryModule {
6763
return this.routeConfigs;
6864
}
6965

70-
getNgComponentByRouteKind(routeKind: RouteKind): Type<Component> | null {
66+
getNgComponentByRouteKind(routeKind: RouteKind): Type<unknown> | null {
7167
return this.routeKindToNgComponent.get(routeKind) || null;
7268
}
7369

tensorboard/webapp/app_routing/views/router_outlet_component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export class RouterOutletComponent implements OnChanges {
3333
@ViewChild('routeContainer', {static: true, read: ViewContainerRef})
3434
private readonly routeContainer!: ViewContainerRef;
3535

36-
@Input() activeNgComponent!: Type<Component> | null;
36+
@Input() activeNgComponent!: Type<unknown> | null;
3737

3838
ngOnChanges(changes: SimpleChanges) {
3939
const activeComponentChange = changes['activeNgComponent'];
4040
if (activeComponentChange) {
4141
this.routeContainer.clear();
4242
const componentType =
43-
activeComponentChange.currentValue as Type<Component> | null;
43+
activeComponentChange.currentValue as Type<unknown> | null;
4444
if (componentType) {
4545
this.routeContainer.createComponent(componentType);
4646
}

tensorboard/webapp/customization/customizable_component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
*
3232
* 1. Define a customizable Component, for example a button:
3333
*
34-
* const CustomizableButton = new InjectionToken<Type<Component>>('Customizable Button');
34+
* const CustomizableButton = new InjectionToken<Type<unknown>>('Customizable Button');
3535
*
3636
* 2. Where the customization point is desired, use this Component to wrap some
3737
* default behavior. Bind to some possibly-empty variable with the
@@ -46,7 +46,7 @@ import {
4646
*
4747
* constructor(
4848
* @Optional() @Inject(CustomizableButton)
49-
* readonly customButtonIfProvided: Type<Component>)
49+
* readonly customButtonIfProvided: Type<unknown>)
5050
*
5151
* If you do not wish to customize the behavior for a certain TensorBoard
5252
* service (in this case, a button), you're done. The TensorBoard service
@@ -85,7 +85,7 @@ import {
8585
`,
8686
})
8787
export class CustomizableComponent implements OnInit {
88-
@Input() customizableComponent!: Type<Component> | undefined;
88+
@Input() customizableComponent!: Type<unknown> | undefined;
8989

9090
constructor(private readonly viewContainerRef: ViewContainerRef) {}
9191

tensorboard/webapp/metrics/views/main_view/main_view_component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ import {
1717
Component,
1818
ElementRef,
1919
EventEmitter,
20-
Input,
2120
Inject,
21+
InjectionToken,
22+
Input,
23+
Optional,
2224
Output,
2325
Type,
24-
Optional,
25-
InjectionToken,
2626
} from '@angular/core';
2727

2828
import {PluginType} from '../../types';
2929
import {CardObserver} from '../card_renderer/card_lazy_loader';
3030

31-
export const SHARE_BUTTON_COMPONENT = new InjectionToken<Type<Component>>(
31+
export const SHARE_BUTTON_COMPONENT = new InjectionToken<Type<unknown>>(
3232
'Customizable Share Button'
3333
);
3434

@@ -62,7 +62,7 @@ export class MainViewComponent {
6262
private readonly host: ElementRef,
6363
@Optional()
6464
@Inject(SHARE_BUTTON_COMPONENT)
65-
readonly customShareButton: Type<Component>
65+
readonly customShareButton: Type<unknown>
6666
) {
6767
this.cardObserver = new CardObserver(
6868
this.host.nativeElement,

tensorboard/webapp/plugins/plugin_registry_module.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
import {
16-
Component,
1716
Inject,
1817
ModuleWithProviders,
1918
NgModule,
2019
Optional,
2120
Type,
2221
} from '@angular/core';
23-
import {PluginConfig, PLUGIN_CONFIG_TOKEN} from './plugin_registry_types';
22+
import {PLUGIN_CONFIG_TOKEN, PluginConfig} from './plugin_registry_types';
2423

25-
const pluginNameToComponent = new Map<string, Type<Component>>();
24+
const pluginNameToComponent = new Map<string, Type<unknown>>();
2625

2726
@NgModule({})
2827
export class PluginRegistryModule {
@@ -40,7 +39,7 @@ export class PluginRegistryModule {
4039

4140
for (const config of configs) {
4241
const {pluginName, componentClass} = config;
43-
pluginNameToComponent.set(pluginName, componentClass as Type<Component>);
42+
pluginNameToComponent.set(pluginName, componentClass as Type<unknown>);
4443
}
4544
}
4645

@@ -71,7 +70,7 @@ export class PluginRegistryModule {
7170
};
7271
}
7372

74-
getComponent(pluginName: string): Type<Component> | null {
73+
getComponent(pluginName: string): Type<unknown> | null {
7574
return pluginNameToComponent.get(pluginName) || null;
7675
}
7776
}

tensorboard/webapp/routes/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
import {Component, Type} from '@angular/core';
15+
import {Type} from '@angular/core';
1616
import {RouteDef} from '../app_routing/route_config_types';
1717
import {RouteKind} from '../app_routing/types';
1818
import {TensorBoardWrapperComponent} from '../tb_wrapper/tb_wrapper_component';
@@ -23,7 +23,7 @@ export function routesFactory(): RouteDef[] {
2323
{
2424
routeKind: RouteKind.EXPERIMENT,
2525
path: '/',
26-
ngComponent: TensorBoardWrapperComponent as Type<Component>,
26+
ngComponent: TensorBoardWrapperComponent as Type<unknown>,
2727
defaultRoute: true,
2828
deepLinkProvider: new DashboardDeepLinkProvider(),
2929
},

0 commit comments

Comments
 (0)