gajus / gajus/flow-runtime

Export Flow types as part of the module

Open
#243 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
797
Forks
49
PR merge metrics
No merged PRs in 30d

Description

This is a:

- [ ] Bug Report
- [x] Feature Request
- [ ] Question
- [ ] Other

Which concerns:

- [x] flow-runtime
- [ ] babel-plugin-flow-runtime
- [ ] flow-runtime-validators
- [ ] flow-runtime-mobx
- [ ] flow-config-parser
- [ ] The documentation website

---

### What is the current behaviour?

Currently, the `flow-runtime` library does not export it's Flow types as part of the module.

---

### What is the expected behaviour?

Incorrect usage of `flow-runtime` without babel should trigger Flow errors.

```js
// @flow

import t, {type Type} from "flow-runtime";

opaque type PositiveNumber: number = number;

// Example refined type.
const PositiveNumberType: Type = t.refinement(
t.number(),
(x: number) => {
if (x < 0) return "must be positive";
}
);

// Signature is accepts(input: any): boolean
// But we're passing more arguments and expecting wrong return type.
const _: string = PositiveNumberType.accepts(1, 2, 3, 4);

// Also should be caught by static Flow checks.
() => PositiveNumberType.methodDoesntExist();
```

---

### Which package versions are you using?

`flow-runtime: 0.17.0`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.