@每日英语4
Get Comfortable with Structural Typing
- Understanding that Javascript is duck typed and Typescript uses structural typing to model this: values assignable to your interfaces might have properties beyond those explicitly listed in your type declaration. Types are not "sealed".
- Be aware that classes also follow structural typing rules. You may not have an instance of the class you expect.
- Use structural typing to facilitate unit testing.
展开
评论