简体   繁体   English

Angular 7+中的ClassDefinition是否有类似的模拟?

[英]Is there any analogue for ClassDefinition in Angular 7+?

I am migrating angular v4 project to a Angular 7. I have faced legacy code and i I can not get rid off that. 我正在将角度v4项目迁移到Angular 7.我已经面临遗留代码,我无法摆脱它。 It has ClassDefinition interface whereas new Angular 7 does not have it. 它有ClassDefinition接口,而新的Angular 7没有它。 How can I deal with this problem? 我该如何处理这个问题? Example of code is shown below. 代码示例如下所示。

I have tried to find out solutions in changelogs of angular documentation but it did not help me at all. 我试图在角度文档的更改日志中找到解决方案,但它根本没有帮助我。

import { ClassDefinition} from "@angular/core";

let componentDefinition: ClassDefinition = {
    constructor: MenuItem
};

If you talk about this: https://v4.angular.io/api/core/ClassDefinition - the first option would be to just declare it in your module: 如果你谈到这个: 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[];
};

After that, you would need to decide how to deal with a situation based on your code base, but what you should know- is that API was marked as stable but then it was deleted by https://github.com/angular/angular/commit/cac130eff9b9cb608f2308ae40c42c9cd1850c4d#diff-635fe23be5795132e3385c8f4899dc3a 在那之后,你需要决定如何根据你的代码库来处理一个情况,但你应该知道的是,API被标记为稳定但是它被https://github.com/angular/angular删除了/提交/ cac130eff9b9cb608f2308ae40c42c9cd1850c4d#DIFF-635fe23be5795132e3385c8f4899dc3a

As you can see - the reason was: 如你所见 - 原因是:

This mode doesn't allow build tools like Webpack to process and optimize the code, which results in prohibitively large bundles. 此模式不允许像Webpack这样的构建工具来处理和优化代码,这会导致过大的捆绑包。 We are removing this API because we are trying to ensure that everyone is on the fast path by default, and it is not possible to get on the fast path using the ES5 DSL. 我们正在删除此API,因为我们正在尝试确保默认情况下每个人都在快速路径上,并且无法使用ES5 DSL进入快速路径。 The replacement is to use TypeScript and @decorator format. 替换是使用TypeScript和@decorator格式。

So you should refactor your legacy code and use TypeScript in the end. 因此,您应该重构遗留代码并最终使用TypeScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM