小编Mic*_*and的帖子

尝试在 Typescript 中覆盖和扩展子类中的方法签名

我有一个要扩展的基类:

export class BaseClass<T extends SomeOtherClass> {
  constructor(param: ParamType) {
  }

  doSomething(param1: Param1Type): BaseClass<T> {
    // do something with param1;
    return this;
  } 
}
Run Code Online (Sandbox Code Playgroud)

我的课:

export class MyClass<T extends SomeOtherClass> extends BaseClass<T> {

  constructor(param: ParamType) {
    super(param);
  }

  doSomething(param1: Param1Type, param2: Param2Type): MyClass<T> {
    // super.doSomething(param1);
    // do something with param2;
    return this;
  }
}
Run Code Online (Sandbox Code Playgroud)

但我收到警告:

Property 'doSomething' in type 'MyClass<T>' is not assignable to the same property in base type 'BaseClass<T>'.
  Type '(param1: Param1Type, param2: Param2Type) => MyClass<T>' is …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance typescript

10
推荐指数
1
解决办法
1万
查看次数

按连续事件分组的第一个和最后一个熊猫之间的差异

我有一个包含打开/关闭、蜡烛颜色和连续蜡烛数量的数据框。

    date open close color  run
00:01:00  100   102     g    1
00:02:00  102   104     g    2
00:03:00  104   106     g    3
00:04:00  106   105     r    1
00:05:00  105   101     r    2
00:06:00  101   102     g    1  
00:06:00  102   103     g    2 
Run Code Online (Sandbox Code Playgroud)

我正在尝试计算运行中第一根蜡烛的开盘价与运行中最后一根蜡烛的收盘价之间的差异的绝对值,并将差异应用于每一行。结果看起来像

    date open close color  run  run_length
00:01:00  100   102     g    1      2        # abs(100 - 102)
00:02:00  102   104     g    2      4        # abs(100 - 104)
00:03:00  104   106     g    3      6        # abs(100 - 106)
00:04:00  106 …
Run Code Online (Sandbox Code Playgroud)

python pandas

5
推荐指数
1
解决办法
2016
查看次数

运行时加载 Typescript 动态模块

我已经BaseClass在 NodeJS Typescript 项目中定义了一个抽象,并且我有一个实现和扩展它的派生类列表BaseClass

// baseModule.ts
export abstract class BaseClass {
  constructor() {}
  abstract method(): void;
}

export interface ModuleConstructor<T extends BaseClass> {
  new (): T
}

export function createModule<T extends BaseClass>(type: ModuleConstructor<T>): T {
  return new type();
}
Run Code Online (Sandbox Code Playgroud)

我试图找到一种在运行时以编程方式创建这些类之一的实例的方法。

这里的限制是我希望能够将一个新myDerivedClass.ts文件放入我的项目文件夹中,并在运行时自动将其包含在可用模块列表中。

开发人员的工作流程是 1) 创建新文件myNewModule.ts2) 创建并导出一个扩展类BaseClass3) 保存myNewModule.ts./myModules

// ./myModules/myNewModule.ts
export class MyModule extends BaseClass {
  constructor() {
    super()
  }

  method() {
    //Do something custom
  }
}
Run Code Online (Sandbox Code Playgroud)

运行时流程(理想情况下无需重建)将是 1) …

dynamic-loading node.js typescript es6-modules

5
推荐指数
1
解决办法
7155
查看次数