facebook / facebook/flow

Treat imported JSON as typed literal

Open
#4,596 5 comments 7 reactions 0 assignees View on GitHub
feature request
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

When importing a JSON module it seems that flow treats its value as an `any` type. It would be great if flow would instead treat it as a typed literal, just like it would if the given object was inlined. E.g.

```javascript
//obj.json
{
"val" : "sadf"
}

//index.js
import obj from 'obj.json';

function double(x : number) {
return x * 2;
}

// $ExpectError
double(obj.val);
// $ExpectError
obj.nonExisting;
// $ExpectError
const key : $Keys = 'notAKey';
```

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.