Typescript doesn't catch `state` type errors outside of constructor?

Viewed 435

enter image description here

In the image above, I have set default state values incorrectly (this_is_not_ok is not part of the State interface). Typescript does not seem to mind, though. One way to fix the issue was to explicitly add a type annotation.

I could also fix the issue by using a constructor():

constructor(){ super(); this.state = {spelling_error: "wrong"}; }

Why did type inference not work in the first example?

1 Answers
Related