子类型与赋值
到目前为止,我们使用的是 "compatible",这不是语言规范中定义的术语。在 TypeScript 中,有两种兼容性:子类型和赋值。这些不同之处仅在于分配扩展了与规则的子类型兼容性,以允许分配到 any
和从 any
分配,以及从 enum
分配相应的数值。
So far, we've used "compatible", which is not a term defined in the language spec. In TypeScript, there are two kinds of compatibility: subtype and assignment. These differ only in that assignment extends subtype compatibility with rules to allow assignment to and from any
, and to and from enum
with corresponding numeric values.
yuY27RerV3BuuSz0R8sIM/SckHe4tqWNSVeK0X3uWai9C3absJipqbQJ2cqO2oTOZPmmiexB2WM3E/13AcDXOQvym6ZOfa7HK3lHVFPlk4+IeTlfP6VbBVZxGY5Tx/6+beER4VT01C+J4cOvQbNOqPpB5cIiD+8999hCHtVon2L67ZPTY7gHAYkI9UfP7iWRJGrCHDfqBoL42IjcznnwWDF0F8ud9cOTy4nxT4dIqHdCbv/inxLpinXXPomQUYCYbF2E7IQjZPTwwxQRyusskmAI4MFRbTMjaqriU1ezDa4MukNh7/z94/VZaF7Glgbf4ODCCe69Nq1++DvFtN+J47Su82CA3+bOG4gX/nwj7ro6D2vNQC7f1YJGx90z0Q4BZUQudBi8i7NDtN06HSfCnBkphpkXsf3AW1CK+0xfnD4kSmBtiVos67xLRUbht1k/2VxmDhXUgb/zQJaNz561MGz3BNvy1yYMNuB/iWIEL7CHwbqza0Yuo8ivIRHjdkCSICFWjxjYY7rYJKbHQVtlKDEzVVlyi38rfmRZrY6Rsd+vu6q7aPazV+xJEPZxOzbBLA58C4uaVlLQLNZ4DkXDtTwTKAsRdc2yKadj60PWIvbyG8Bk0WKLf2O0aHv658N9iAKQcBZ9xapXc9QQ+kocbaImBNJxGdg3totMQFwh26lQJr9YP2AsPz8r+fAS+0zVTDXLl8WMbD/XsJM5Pe8O7w==