fix(ivy): remove metadata from *Def and introduce *DefWithMeta types (#26203)
Previously in Ivy, metadata for directives/components/modules/etc was carried in .d.ts files inside type information encoded on the DirectiveDef, ComponentDef, NgModuleDef, etc types of Ivy definition fields. This works well, but has the side effect of complicating Ivy's runtime code as these extra generic type parameters had to be specified as <any> throughout the codebase. *DefInternal types were introduced previously to mitigate this issue, but that's the wrong way to solve the problem. This commit returns *Def types to their original form, with no metadata attached. Instead, new *DefWithMeta types are introduced that alias the plain definition types and add extra generic parameters. This way the only code that needs to deal with the extra metadata parameters is the compiler code that reads and writes them - the existence of this metadata is transparent to the runtime, as it should be. PR Close #26203
This commit is contained in:

committed by
Jason Aden

parent
b0070dfb9a
commit
79466baef8
@ -59,11 +59,9 @@ export const enum DirectiveDefFlags {ContentQuery = 0b10}
|
||||
*/
|
||||
export interface PipeType<T> extends Type<T> { ngPipeDef: never; }
|
||||
|
||||
/**
|
||||
* A version of {@link DirectiveDef} that represents the runtime type shape only, and excludes
|
||||
* metadata parameters.
|
||||
*/
|
||||
export type DirectiveDefInternal<T> = DirectiveDef<T, string>;
|
||||
export type DirectiveDefWithMeta<
|
||||
T, Selector extends string, ExportAs extends string, InputMap extends{[key: string]: string},
|
||||
OutputMap extends{[key: string]: string}, QueryFields extends string[]> = DirectiveDef<T>;
|
||||
|
||||
/**
|
||||
* Runtime information for classes that are inherited by components or directives
|
||||
@ -110,12 +108,12 @@ export interface BaseDef<T> {
|
||||
*
|
||||
* See: {@link defineDirective}
|
||||
*/
|
||||
export interface DirectiveDef<T, Selector extends string> extends BaseDef<T> {
|
||||
export interface DirectiveDef<T> extends BaseDef<T> {
|
||||
/** Token representing the directive. Used by DI. */
|
||||
type: Type<T>;
|
||||
|
||||
/** Function that makes a directive public to the DI system. */
|
||||
diPublic: ((def: DirectiveDef<T, string>) => void)|null;
|
||||
diPublic: ((def: DirectiveDef<T>) => void)|null;
|
||||
|
||||
/** The selectors that will be used to match nodes to this directive. */
|
||||
selectors: CssSelectorList;
|
||||
@ -172,11 +170,9 @@ export interface DirectiveDef<T, Selector extends string> extends BaseDef<T> {
|
||||
features: DirectiveDefFeature[]|null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A version of {@link ComponentDef} that represents the runtime type shape only, and excludes
|
||||
* metadata parameters.
|
||||
*/
|
||||
export type ComponentDefInternal<T> = ComponentDef<T, string>;
|
||||
export type ComponentDefWithMeta<
|
||||
T, Selector extends String, ExportAs extends string, InputMap extends{[key: string]: string},
|
||||
OutputMap extends{[key: string]: string}, QueryFields extends string[]> = ComponentDef<T>;
|
||||
|
||||
/**
|
||||
* Runtime link information for Components.
|
||||
@ -190,7 +186,7 @@ export type ComponentDefInternal<T> = ComponentDef<T, string>;
|
||||
*
|
||||
* See: {@link defineComponent}
|
||||
*/
|
||||
export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T, Selector> {
|
||||
export interface ComponentDef<T> extends DirectiveDef<T> {
|
||||
/**
|
||||
* Runtime unique component ID.
|
||||
*/
|
||||
@ -289,13 +285,13 @@ export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T
|
||||
*
|
||||
* See: {@link definePipe}
|
||||
*/
|
||||
export interface PipeDef<T, S extends string> {
|
||||
export interface PipeDef<T> {
|
||||
/**
|
||||
* Pipe name.
|
||||
*
|
||||
* Used to resolve pipe in templates.
|
||||
*/
|
||||
name: S;
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Factory function used to create a new pipe instance.
|
||||
@ -314,10 +310,10 @@ export interface PipeDef<T, S extends string> {
|
||||
onDestroy: (() => void)|null;
|
||||
}
|
||||
|
||||
export type PipeDefInternal<T> = PipeDef<T, string>;
|
||||
export type PipeDefWithMeta<T, Name extends string> = PipeDef<T>;
|
||||
|
||||
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T, string>) => void;
|
||||
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) => void;
|
||||
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
|
||||
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
|
||||
|
||||
/**
|
||||
* Type used for directiveDefs on component definition.
|
||||
@ -326,12 +322,12 @@ export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) =>
|
||||
*/
|
||||
export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList;
|
||||
|
||||
export type DirectiveDefList = (DirectiveDef<any, string>| ComponentDef<any, string>)[];
|
||||
export type DirectiveDefList = (DirectiveDef<any>| ComponentDef<any>)[];
|
||||
|
||||
export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
|
||||
|
||||
export type DirectiveTypeList =
|
||||
(DirectiveDef<any, string>| ComponentDef<any, string>|
|
||||
(DirectiveDef<any>| ComponentDef<any>|
|
||||
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
|
||||
|
||||
/**
|
||||
@ -341,13 +337,12 @@ export type DirectiveTypeList =
|
||||
*/
|
||||
export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList;
|
||||
|
||||
export type PipeDefList = PipeDefInternal<any>[];
|
||||
export type PipeDefList = PipeDef<any>[];
|
||||
|
||||
export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
|
||||
|
||||
export type PipeTypeList =
|
||||
(PipeDefInternal<any>|
|
||||
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
|
||||
(PipeDef<any>| Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
|
||||
|
||||
|
||||
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
||||
|
@ -12,7 +12,7 @@ import {Sanitizer} from '../../sanitization/security';
|
||||
import {PlayerHandler} from '../interfaces/player';
|
||||
|
||||
import {LContainer} from './container';
|
||||
import {ComponentQuery, ComponentTemplate, DirectiveDefInternal, DirectiveDefList, PipeDefInternal, PipeDefList} from './definition';
|
||||
import {ComponentQuery, ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDef, PipeDefList} from './definition';
|
||||
import {LElementNode, LViewNode, TElementNode, TNode, TViewNode} from './node';
|
||||
import {LQueries} from './query';
|
||||
import {Renderer3} from './renderer';
|
||||
@ -558,10 +558,10 @@ export type HookData = (number | (() => void))[];
|
||||
*
|
||||
* Injector bloom filters are also stored here.
|
||||
*/
|
||||
export type TData = (TNode | PipeDefInternal<any>| number | null)[];
|
||||
export type TData = (TNode | PipeDef<any>| number | null)[];
|
||||
|
||||
/** Type for TView.currentMatches */
|
||||
export type CurrentMatchesList = [DirectiveDefInternal<any>, (string | number | null)];
|
||||
export type CurrentMatchesList = [DirectiveDef<any>, (string | number | null)];
|
||||
|
||||
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
||||
// failure based on types.
|
||||
|
Reference in New Issue
Block a user