LianwenWu
LianwenWu

Reputation: 9

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!

Upvotes: 0

Views: 196

Answers (1)

tenshi
tenshi

Reputation: 26404

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.

Upvotes: 1

Related Questions