Created by: puxiao
I ran into a problem yesterday, as follows:
type XxxType = 'aaa' | 'bbb' | 'ccc'
interface Xxx {
type: XxxType
}
interface MyXxx {
name: string
xxx: Xxx
}
interface MyObj {
arr: Iterable<MyXxx>
}
const myObj: MyObj = {
arr: [ { name: 'aaa', xxx: { type: 'aaa' } } ]
}
emm...
Type '{ name: string; xxx: { type: string; }; }[]' is not assignable to type 'Iterable<MyXxx>'.
...
Type 'string' is not assignable to type 'XxxType'. ts[2322]
It's maddening and unbelievable.
I think there is nothing wrong with what I wrote.
Finally, I found the reason.
{
"compilerOptions": {
- "target": "es5",
+ "target": "es6",
...
}
}
ES6 also called ES2015
ES5 seems like a very long time ago. So I suggest changing the default ES5 to ES6.