facebook / facebook/flow

Treat imported JSON as typed literal

Offen
#4,596 5 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
feature request
Vorherrschende Sprache
Rust
Sterne
22.3k
Forks
1.9k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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';
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.