[英]Is there any analogue for ClassDefinition in Angular 7+?
我正在将角度v4项目迁移到Angular 7.我已经面临遗留代码,我无法摆脱它。 它有ClassDefinition接口,而新的Angular 7没有它。 我该如何处理这个问题? 代码示例如下所示。
我试图在角度文档的更改日志中找到解决方案,但它根本没有帮助我。
import { ClassDefinition} from "@angular/core";
let componentDefinition: ClassDefinition = {
constructor: MenuItem
};
如果你谈到这个: https : //v4.angular.io/api/core/ClassDefinition - 第一个选择就是在你的模块中声明它:
/**
* Declares the interface to be used with {@link Class}.
*
* @stable
*/
export type ClassDefinition = {
/**
* Optional argument for specifying the superclass.
*/
extends?: Type<any>;
/**
* Required constructor function for a class.
*
* The function may be optionally wrapped in an `Array`, in which case additional parameter
* annotations may be specified.
* The number of arguments and the number of parameter annotations must match.
*
* See {@link Class} for example of usage.
*/
constructor: Function | any[];
} &
{
/**
* Other methods on the class. Note that values should have type 'Function' but TS requires
* all properties to have a narrower type than the index signature.
*/
[x: string]: Type<any>|Function|any[];
};
在那之后,你需要决定如何根据你的代码库来处理一个情况,但你应该知道的是,API被标记为稳定但是它被https://github.com/angular/angular删除了/提交/ cac130eff9b9cb608f2308ae40c42c9cd1850c4d#DIFF-635fe23be5795132e3385c8f4899dc3a
如你所见 - 原因是:
此模式不允许像Webpack这样的构建工具来处理和优化代码,这会导致过大的捆绑包。 我们正在删除此API,因为我们正在尝试确保默认情况下每个人都在快速路径上,并且无法使用ES5 DSL进入快速路径。 替换是使用TypeScript和
@decorator
格式。
因此,您应该重构遗留代码并最终使用TypeScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.