Skip to content

Treat imported JSON as typed literal #4596

@TiddoLangerak

Description

@TiddoLangerak

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.

//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<typeof obj> = 'notAKey';

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions