facebook / facebook/flow

Flow fails to check Disjoint Unions as object value type

Open
#1,959 11 comments 0 reactions 0 assignees View on GitHub
Typing: unions/intersections
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

``` javascript
type ASTLiteralNode = {
type: 'Literal',
value: any
};

type ASTThisNode = {
type: 'ThisExpression'
};

class AST {
static Literal = 'Literal';
static ThisExpression = 'ThisExpression';

static constants: { [key: string]: (ASTThisNode | ASTLiteralNode) } = {
'this': { type: AST.ThisExpression },
'null': { type: AST.Literal, value: null },
'true': { type: AST.Literal, value: true },
'false': { type: AST.Literal, value: false }
};
}
```

I got the errors:

```
src/parse.js:242
242: 'null': { type: AST.Literal, value: null },
^^^^^^^^^^^ string. Expected string literal `ThisExpression`, got `Literal` instead
228: type: 'ThisExpression'
^^^^^^^^^^^^^^^^ string literal `ThisExpression`

src/parse.js:243
243: 'true': { type: AST.Literal, value: true },
^^^^^^^^^^^ string. Expected string literal `ThisExpression`, got `Literal` instead
228: type: 'ThisExpression'
^^^^^^^^^^^^^^^^ string literal `ThisExpression`

src/parse.js:244
244: 'false': { type: AST.Literal, value: false }
^^^^^^^^^^^ string. Expected string literal `ThisExpression`, got `Literal` instead
228: type: 'ThisExpression'
^^^^^^^^^^^^^^^^ string literal `ThisExpression`
```

Also, I have enabled `esproposal.class_instance_fields` and `esproposal.class_static_fields` in `.flowconfig`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.