Skip to content

Commit ebf6516

Browse files
dgp1130thePunderWoman
authored andcommitted
refactor(devtools): make component-only properties on DirectiveMetadata optional (angular#60475)
This type was incorrect, as only components have `encapsulation` and `onPush` values. `ng.getDirectiveMetadata` does not return these properties for directive inputs. Unfortunately the `| Partial<AngularComponentDebugMetadata>` is necessary to reference these properties or else TypeScript will reject their usage. PR Close angular#60475
1 parent ab9dd73 commit ebf6516

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

devtools/projects/ng-devtools-backend/src/lib/component-tree.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
Type,
1717
ValueProvider,
1818
ɵAngularComponentDebugMetadata as AngularComponentDebugMetadata,
19+
ɵAngularDirectiveDebugMetadata as AngularDirectiveDebugMetadata,
1920
ɵProviderRecord as ProviderRecord,
2021
} from '@angular/core';
2122
import {
@@ -219,7 +220,9 @@ const enum DirectiveMetadataKey {
219220
// the method directly interacts with the directive/component definition.
220221
const getDirectiveMetadata = (dir: any): DirectiveMetadata => {
221222
const getMetadata = ngDebugClient().getDirectiveMetadata!;
222-
const metadata = getMetadata?.(dir) as AngularComponentDebugMetadata;
223+
const metadata = getMetadata?.(dir) as
224+
| (AngularDirectiveDebugMetadata & Partial<AngularComponentDebugMetadata>)
225+
| null;
223226
if (metadata) {
224227
return {
225228
inputs: metadata.inputs,
@@ -249,7 +252,7 @@ const getDirectiveMetadata = (dir: any): DirectiveMetadata => {
249252

250253
export function isOnPushDirective(dir: any): boolean {
251254
const metadata = getDirectiveMetadata(dir.instance);
252-
return metadata.onPush;
255+
return Boolean(metadata.onPush);
253256
}
254257

255258
export function getInjectorProviders(injector: Injector) {

devtools/projects/protocol/src/lib/messages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ export interface DirectivesProperties {
102102
export interface DirectiveMetadata {
103103
inputs: {[name: string]: string};
104104
outputs: {[name: string]: string};
105-
encapsulation: ViewEncapsulation;
106-
onPush: boolean;
105+
encapsulation?: ViewEncapsulation;
106+
onPush?: boolean;
107107
dependencies?: SerializedInjectedService[];
108108
}
109109

0 commit comments

Comments
 (0)