facebook / facebook/flow

Recursive generics

Open
#4,955 0 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Not sure if it's a bug or a feature request, since neither way of defining a recursive generic type is in the documentation, afaik.

[A generic's qualification cannot reference itself:
](https://flow.org/try/#0GYVwdgxgLglg9mABMOcA8AVAXIg3gIwEMAnAfhwwF8A+ACgEpdKg
)
```
1: function foo(){}
^ identifier `T`. Could not resolve name
```

[But a type definition can:
](https://flow.org/try/#0C4TwDgpgBAcg9gEwgHgCoD4oF4oG8BQUUARgIYBOAXLIihvgL74BmArgHYDGwAlnO1GZw4yAOroAFO1rV4SMegCUuBkA)
```flow
type Node = {
bar: Node
}
function foo(node: Node){}
```
Judging by the fact the latter is implemented, it shouldn't be hard to add.

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.