'Flow to Typescript

I now have flow type code like this

export interface NodeBase {
  start: number;
  end: number;
}
export type Node = NodeBase & { [key: string]: any };

Then I used this in the function

  finishNodeAt<T: NodeType>(node: T,type: string): T {
    node.type = type;
    return node;
  }

There is no colon syntax in typescript and I'm not very familiar with flow. Could you please teach me how to convert this to the corresponding typescript code? Kind Regards!



Solution 1:[1]

This Flow type should represent the same thing in TypeScript and it's the same syntax:

export interface NodeBase {
  start: number;
  end: number;
}

export type Node = NodeBase & { [key: string]: any };

Nothing to change here.

The one thing that needs changing is the generic:

  finishNodeAt<T extends NodeType>(node: T,type: string): T {
    node.type = type;
    return node;
  }

We use extends instead of a colon to specify generic constraints.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hittingonme