I have json file test.json
{ "foo": "bar0" }
Given those types declaration
type Bar = 'bar0' | 'bar1'
interface Foo {
foo: Bar
}
I tried to load this json
import test from './test.json'
const foo: Foo = test
And I got this error
Type '{ "foo": string; }' is not assignable to type 'Foo'.
Types of property 'foo' are incompatible.
Type 'string' is not assignable to type 'Bar'.
I also tried with enum
enum Bar {
bar0 = 'bar0',
bar1 = 'bar1'
}
Of course it works with type Bar = string
Any idea about what can be wrong?
foois a string, while your typeBaris a string literal. It's the same problem but just different ways of getting it.