Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

补充接口说明 #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions basics/type-of-object-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ let tom: Person = {

接口一般首字母大写。[有的编程语言中会建议接口的名称加上 `I` 前缀](https://msdn.microsoft.com/en-us/library/8bc1fexb%28v=vs.71%29.aspx)。

定义接口时,属性之间可以用分号 `;` 分隔,也可以用逗号 `,` 分隔,甚至什么都不加也可以。

可以使用匿名接口定义对象的类型:

```ts
let tom: {
name: string;
age: number;
} = {
name: 'Tom',
age: 25
};
```

上面的例子中,我们使用匿名接口约束了 `tom` 的形状,效果与使用已定义的接口完全一致。

定义的变量比接口少了一些属性是不允许的:

```ts
Expand Down