Kyle
Kyle

Reputation: 4024

Why doesn't this type check, but a variation of it does?

I'm not sure if this is a bug or not, so I thought I'd ask here.

I have this code which fails to type check:

/* @flow */
declare type A = {
    code: ?number;
}

var a: A = {}

But if I make a class with the same signature as the type A, and instantiate it, then it type checks:

/* @flow */
declare type A = {
    code: ?number;
}

class _A {
    code: ?number;
}

var a: A = new _A();

The type check error that I'm getting on the first variant is this:

test.js:2:19,4:2: property code
Property not found in
test.js:6:13,14: object literal

I feel like this is a bug, but I could be wrong.

Upvotes: 1

Views: 184

Answers (1)

Kyle
Kyle

Reputation: 4024

I figured it out by re-reading the docs. The syntax for optional properties isn't:

{code:?number}

but instead is:

{code?:number}

Oops.

Upvotes: 2

Related Questions