facebook / facebook/flow

Type information lost when using opaque subtype constraint for another opaque type

Open
#4,674 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

### flow code

#### bytes.js
```
export type BytesRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32

export opaque type Bytes : string = string

export opaque type BytesN : Bytes = Bytes
```

#### address.js
```
...

export const bytesToAddressTruncate = (bts: Bytes): Address => {
...
};
```

### expected result

It should be possible to pass a `BytesN` Into a function taking `Bytes`, such as `bytesToAddressTruncate` above.

### actual result

Values are considered strings, ie the subtype's subtype - similar to how you couldn't pass them through functions earlier (https://github.com/facebook/flow/issues/4640).

```
Error: src/abi/Event.js:95
95: address = bytesToAddressTruncate(b);
^ string. This type is incompatible with the expected param type of
46: export const bytesToAddressTruncate = (bts: Bytes): Address => {
^^^^^ opaque type `Bytes`. See: src/types/address.js:46
```

### spec

#### OS
Windows 10, 64 bits

#### Node.js
```
>node --version
v8.2.1
```
#### flow
```
>.\node_modules\.bin\flow.cmd version
Flow, a static type checker for JavaScript, version 0.53.1
```

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.