簡體   English   中英

Angular 7+中的ClassDefinition是否有類似的模擬?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM