dknaack
dknaack

Reputation: 60556

Flow Type casting

I am coming from Typescript and trying Flow Type right now.

In TypeScript i can do this.

interface x {
    name: string;
}

let y = <x> {
    name: "John Doe"
};

How can i do this with flow type?

On Flow - Announcing Typecasts i saw that flow's syntax for casts is e.g.

(myVar: myType)

but

let y = {
    name: "John Doe"
}: x;

does not work.

Upvotes: 1

Views: 1458

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221412

The parentheses are mandatory. Use

let y = ({
    name: "John Doe"
}: x);

Upvotes: 7

Related Questions