facebook / facebook/flow

Function Generic parameter is resolved to void

Open
#8,190 2 comments 0 reactions 0 assignees View on GitHub
bug Typing: functions
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Flow version: v0.102.0

## Expected behavior

Function Generic parameter is resolved to void

- [flow try](https://flow.org/try/#0GYVwdgxgLglg9mABMMAeAKgPgBQEMBci6AlIgN4BQiATgKZQjVK4DcFAvhRQPTeIDKACzggANgBNEtatTjUKKbMRZA)
```typescript
function fn(a: T) {
return a;
}

// Should error
fn();
```

- [flow try](https://flow.org/try/#0GYVwdgxgLglg9mABMMAKAhgLkQfgM5QBOMYA5gJSIDeAUIoQKZQiFLoDcNAvjTQPR9EAZQAWcEABsAJogaFCcQjRSpy7IA)
```typescript
function fn(a: ?string) {
return a;
}

// Should error
fn();
```

- [flow try](https://flow.org/try/#0GYVwdgxgLglg9mABMMAeAKgPgBQEMD8AXIgCQByCAsrgJ4BGApujQA4MaYCUiA3gFCIATgyghBSXAG4+AXz58A9AsQAxOABt1cAO4wwAc0QBnKLigMAtgzBRjACzgh1AE0QNBguIMR5EMI0IMAI4gMMLOnHwo2JzSfEA)
```typescript
function fn(a?: $NonMaybeType) {
return a;
}

// Should error
fn();
```

- [flow try](https://flow.org/try/#0CYUwxgNghgTiAEAzArgOzAFwJYHtXwAcYcCBlKbAZ0SxEoB4AVAGngGkA+ACgCh54weYAC54XAB6iAJAFEIIALYhUGRgE8CIJq04BKeAF4O8AEY4c8qKmZ9CxAqLY3+OUYx67RZiyCsBuHj5QSFgEFHRsPHgsSgA5LAgJUQUscRBgT1NzS3wAUjAAC3AAa0oJQwMDeDRQGlR0+AAfRtt+cQqq1GQICF0AngB6AfhSApxu4HgQGGIYHkFUSgxTeGFvHMM7EnIqGjouGPiIVgBycRO+oA)
```typescript
declare function propSatisfies(
cond: (x: $ElementType) => boolean,
prop: K,
o: T
): boolean;

declare function isNil(x: mixed): boolean %checks(x === undefined ||
x === null);

// Should error
const b :boolean = propSatisfies(isNil, 'x');
```

## Actual behavior

None of the previous statements errors. As we can explicitly define optional parameters as follow, we can assume parameter is required by default.

```typescript
function fn(a?: ?string) {
return a;
}

fn();
```

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.