JavaScript/typescript/interface:修订间差异
来自康健生活
创建页面,内容为“== 引言 == == 示例 == 描述一个对象或者函数。 <syntaxhighlight lang="javascript"> interface User { name: string age: number } interface SetUser {…” |
|||
| (未显示同一用户的1个中间版本) | |||
| 第5行: | 第5行: | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
interface | interface Engineer { | ||
name: string | name: string; | ||
age: number | age: number; | ||
}; | |||
interface SetEngineer { | |||
(name: string, age: number): void; | |||
};</syntaxhighlight> | |||
=== 拓展 === | |||
<syntaxhighlight lang="javascript"> | |||
interface Engineer { | |||
name: string; | |||
} | |||
interface BackendEngineer extends Engineer { | |||
age: number; | |||
}</syntaxhighlight> | |||
==== 结合 ==== | |||
[[JavaScript/typescript/type#结合|结合]] | |||
== 声明 == | |||
=== 声明结合 === | |||
<syntaxhighlight lang="javascript"> | |||
interface Engineer { | |||
name: string; | |||
age: number; | |||
} | |||
interface Engineer { | |||
profession?: string; | |||
} | } | ||
interface | /* | ||
// 等价于 | |||
}</syntaxhighlight> | interface Engineer { | ||
name: string; | |||
age: number; | |||
profession?: string; | |||
} | |||
*/</syntaxhighlight> | |||