Why does typescript implicitly convert between unrelated classes?

前端 未结 1 339
借酒劲吻你
借酒劲吻你 2021-01-18 06:47

Typescript (1.4 & whatever version is powering the typescriptlang.org playground) does not generate a compiler error on code that seems wrong with respect to implicit ty

相关标签:
1条回答
  • 2021-01-18 07:41

    TypeScript uses a structural type system. Classes with identical properties are considered to be identical for the purposes of typechecking. It's better to think of instanceof as a runtime check about the prototype chain rather than a statement about what fields an object has or doesn't have.

    0 讨论(0)
提交回复
热议问题