У меня есть файл json test.json
{ "foo": "bar0" }
Учитывая объявление этих типов
type Bar = 'bar0' | 'bar1'
interface Foo {
foo: Bar
}
Я пытался загрузить этот json
import test from './test.json'
const foo: Foo = test
И я получилэта ошибка
Type '{ "foo": string; }' is not assignable to type 'Foo'.
Types of property 'foo' are incompatible.
Type 'string' is not assignable to type 'Bar'.
Я также пытался с enum
enum Bar {
bar0 = 'bar0',
bar1 = 'bar1'
}
Конечно, это работает с type Bar = string
Любая идея о том, что может быть не так?